Git ignores deleted file on merge

Solution 1:

The issue here is your use of squash commits.

When you do a merge --squash, you abandon all of the history of a branch. You haven't really "merged the branch" - you've just applied a condensed representation of its history. So if you do a later merge --squash, git will reapply all the commits in the branch's history (since the two branches have no common ancestor).

When you perform the first merge --squash, you create a commit on main which contains "Create one, two, and three". So the history of main is first "create four", then "create one, two, and three".

When you do the second merge --squash, you add a commit which consists of (in effect) "Create one, two, and three" plus "Remove two". The net of those two commits together (squashed!) is "Create one and three". So git auto-merges the "Create one and three" commit with your current repo state - leaving you with four files present. The content merge succeeds automatically because the files "one" and "three" are identical on both sides.

You should use "real" merges or cherry-picking instead of squashing if you want to keep a repo up-to-date with a remote. A merge --squash is not the same thing as "play through all the new commits in a remote repository and integrate them here".