开发者

Why does this merge produce a conflict

When I run this command:

 git log HEAD..other_branch -- some_file.txt

There's no output at all which I assume meants that there were no changes to som开发者_如何学Goe_file.txt in other_branch. Yet when I run git merge other_branch I get a whole slew of conflicts in some_file.txt.

When I run:

git log HEAD...other_branch -- some_file.txt 

I get two commits. One where the file was modified and one where the branch where it was modified was merged into HEAD.

I assumed that because the file was only changed in one branch that there wouldn't be any conflicts. Why are there conflicts? Is there a way to see what will conflict (and why) before I run git merge?


To add to manojlds's contribution:

Very nice. But then the following should accomplish the same?

git diff master:some_file.txt someBranch:some_file.txt

that way you don't need to checkout before diffing against cached


Original answer:

The command

git log HEAD..other_branch -- some_file.txt

is identical to

git log ^HEAD other_branch -- some_file.txt

which means give me the log of all commits reachable from other_branch but NOT reachable from HEAD for some_file.txt. If this command gives you no output, it means that some_file.txt has not changed on other_branch at all.

On the other hand:

git log HEAD...other_branch -- some_file.txt 

is the symmetric difference between HEAD and other_branch, i.e. the commits that are in HEAD and in other_branch but not in both, and are the commits that will be merged when you merge the two branches. So something has probably happened to some_file.txt on HEAD that cause this conflict with the version on other_branch


To add to @Magnus Skog's answer and your question:

I assumed that because the file was only changed in one branch that there wouldn't be any conflicts. Why are there conflicts? Is there a way to see what will conflict (and why) before I run git merge?

In such cases I would mostly do:

git checkout other_branch some_file.txt

Then do

git diff --cached some_file.txt

to see the diffs and you can easily see if you get merge conflicts. If you also wanted to just "merge" the file alone, you can git commit now.

This is the approach I take when seeing differences in certain file(s) and also merging specific file(s)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜