I seem to have run into a case where git doesn’t notice inline changes when merging..
My master branch had a file with this line:
process &block if block
And I did a fetch from a git repo, and tried to merge in the changes from the same file, which had a line with:
process 1, &block if block
But git didn’t give a warning about a possible merge conflict, and didn’t highlight the line as changed [1]. The change was simply ignored, not updating the file with the line [2].
Why did git not notice this inline change? And update the line (since the line was from a later commit)?
EDIT:
[1] – git didn’t indicate that it had changed when I was doing the conflict resolution (you know, it didn’t put in “<<<” in the source code around it). And the succeeding merge commit doesn’t show the line as changed in any way (either when running gif diff with colors or looking at the code on github).
[2] – The line came from a repo which held a newer version of the same gem I was working on (so there should be some common commit ancestors with which to do the merge. Also, the line was updated in a later commit on that same repo, so it should be apparent for git that that was in fact an update).
EDIT:
In case it plays a role, this was the commit tree before the merge:
The original gem (common ancestry):
--A
My master branch (actually a fork of the original gem):
--A--
\
--B
(the line wasn’t changed in B, but came from A)
The repo I merged into master (the updated version of the gem):
--A---C---D
(the line was updated in D)
Merge, git or otherwise (sans bugs or incomplete implementations), works by looking up most recent common ancestor of the two branches and than combines changes since that point. It is only a conflict if both sides changed the line (in different way). If only one side changed it, that change is applied.
In git, you can see changes from merge base to the branch head you want to merge using
git diff HEAD...branchand changes from merge base to your local head usinggit diff branch...HEAD(generally,git diffleft...right shows changes from common ancestor of left and right to right). The commands are for before you do the merge. After the fact, it would begit diff HEAD^..HEAD^2andgit diff HEAD^2..HEAD^(HEAD^is first parent,HEAD^2is right parent).You can also see all revisions since the merge base by replacing
git diffwithgitkin above commands or just ask for what the mere base is usinggit merge-base HEAD branch.