joachim
joachim

Reputation: 30831

git merge commit removes files, but `git show SHA` doesn't show them being removed

I have this situation in git:

-F--M--F1-->
   /
  /
-D--D1-->

If I checkout F, I see the file. If I checkout M, the file is gone.

But git show --name-status M does NOT show the file being removed. It instead shows two other files with 'MM' (literally) in the status column, meaning both sides had changes in the merge.

What is happening? How is the file removed in commit M without git showing it as removed?

Upvotes: 2

Views: 45

Answers (2)

j6t
j6t

Reputation: 13507

git show on a merge commit is very special. Only those files are shown that are different from both parents. In your case, the deleted file is "identical" to one of the parents (i.e., it is deleted in one parent, D, and deleted in the result M), so it is not shown.

There is a mode that can help:

git show -m M

This computes a diff to each parent and shows them as a separate patch (or whatever display mode you choose).

Upvotes: 2

Sergi
Sergi

Reputation: 78

You probably merged the main branch into the feature branch, not the other way around
So the file is only visible to F

Upvotes: 0

Related Questions