Why does this merger give rise to conflict

When I run this command:

git log HEAD..other_branch -- some_file.txt 

There is no conclusion that I assume that there are no changes to some_file.txt in other_branch . However, when I run git merge other_branch , I get an integer number of conflicts in some_file.txt.

When I run:

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

I get two commits. Where the file was changed, and the one where the branch where it was changed was merged with HEAD.

I assumed that since the file was modified in only one branch, there were no conflicts between them. Why are there conflicts? Is there a way to see what will conflict (and why) before running git merge ?

+6
source share
2 answers

To add to the contribution manojlds:

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

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

this way you don't need to check before using caching


Original answer:

Command

 git log HEAD..other_branch -- some_file.txt 

coincides with

 git log ^HEAD other_branch -- some_file.txt 

which means giving me a log of all the commits available from other_branch but not accessible from HEAD for some_file.txt. If this command does not give you an exit, it means that some_file.txt has not changed at all to other_branch.

On the other hand:

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

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

+4
source

To add to @Magnus Skog the answer and your question:

I assumed that since the file was in only one branch, there would be no conflict. Why are there conflicts? Is there any way to see what would be conflicting (and why) before I run git merge?

In such cases, I would basically do:

 git checkout other_branch some_file.txt 

Then do

 git diff --cached some_file.txt 

to see the differences, and you can easily see if you have merge conflicts. If you also wanted to just β€œmerge” the file alone, now you can git commit .

This is the approach that I take when I see differences in certain files, as well as merging certain files

+1
source

Source: https://habr.com/ru/post/887090/


All Articles