RamiR
RamiR

Reputation: 339

File deleted during merge conflict resolving is not shown on merge commit

We had strange issue when merging two branches on git. File was deleted during merge even though I couldn't find a commit where the file was deleted. After an investigation I did find out that files do disappear on one of the merge commits even though commit doesn't list any changes to the file. This must be because developer has deleted the file while resolving a merge conflict. To prove this I created a git repo and tested with these commands:

git init
echo foo >> first_file
git add .
git commit -am "add first file"
git checkout -b topic_branch
echo bar >> second_file
echo bar >> first_file
git add .
git commit -am "add second file and change the first"
git checkout master
echo conflict >> first_file
git commit -am "create conflict"
git merge topic_branch 
rm second_file 
echo conflict >> first_file
git add first_file 
git commit
git show

As you see I created two files on two branches. One that will deliberately create merge conflict and second file on the topic_branch. I delete the second_file while resolving the merge conflict. Now what I don't understand is that why git show doesn't mention anything about deleting the second_file. Is there any way to see what actually did happen on the merge?

Upvotes: 1

Views: 168

Answers (1)

torek
torek

Reputation: 489083

When git show displays a merge commit, it uses a combined diff by default.

There are several different combined diff formats, but they all share one feature (or bug depending on what you think of it): they never show any file whose merged version exactly matches at least one parent version. Since one parent version of the file is "there is no such file", and the merge version of the file is "there is no such file", and these match, git show does not show anything for this file.

To make git show show something for this file, make it produce one diff per parent commit, using git show -m.

Upvotes: 1

Related Questions