Git tells me that I am merging a conflict, but also tells me that no files need merging

I made some changes in the new branch.

I go out to master .

When I tried to merge:

 $ git merge new Auto-merging js/site.js CONFLICT (content): Merge conflict in js/site.js Automatic merge failed; fix conflicts and then commit the result. 

So, I installed kdiff3 and configured my configuration files, and when I tried to use mergetools, I got:

 $ git mergetool kdiff3 No files need merging 

I ran diff and it output this:

 diff --cc js/site.js index 8c17d62,7955b13..0000000 --- a/js/site.js +++ b/js/site.js @@@ -72,4 -81,18 +81,22 @@@ function doSmallScreen() $(document).ready(function () { calculateScreen(); - }); ++<<<<<<< HEAD ++}); ++======= + $(window).resize(function () { + delay(function () { + calculateScreen(); + }, 500); + }); + }); + + + var delay = (function () { + var timer = 0; + return function (callback, ms) { + clearTimeout(timer); + timer = setTimeout(callback, ms); + }; -})(); ++})(); ++>>>>>>> new 

I am confused about how to solve this, I want to solve it in the easiest way, I don’t care if I lose information from the new branch, but I want to understand what went wrong and why I can not use the merge tools.

It just seems strange to me that I have a merge conflict, but the files do not need to be merged.

+10
source share
3 answers

I think your mergetool command is wrong. Must be

 $ git mergetool 

or

 $ git mergetool --tool=kdiff3 

If you are stuck with the git command, you can always check the manual ( git mergetool --help ).

Additional information: https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

+5
source

I tried

 git mergetool . 

It seemed to work.

+9
source

I had this problem even when I just ran the correct command:

 $ git mergetool 

This may be due to the inclusion of the rerere function (see this link [Ed .: link no longer works])

I solved the problem by creating two aliases in .gitconfig , which .gitconfig mergetool for each conflicting file:

Add this to your .gitconfig

 # List conflicted files list-conflicts = !git ls-files -u | cut -f 2 | sort -u # Force mergetool to recognize conflicts force-mergetool = !git list-conflicts | xargs git mergetool 

TL; etc. Optionally, here is a brief explanation of what this does:

  • git ls-files -u : after an attempt to merge with conflicts, it lists all non-merged files, as well as some extraneous information and repetitions; if you run immediately after the merge, this is essentially all files with conflicts
  • | cut -f 2 | cut -f 2 | cut -f 2 | cut -f 2 cuts | cut -f 2 | cut -f 2 field of this output, which is essentially the file path
  • | sort -u | sort -u | sort -u | sort -u eliminates duplicates
  • | xargs git mergetool | xargs git mergetool | xargs git mergetool | xargs git mergetool this list of files to the mergetool command, which launches the GUI merge tool (assuming you have one)

This way you can run the first command if you just want to see the files in the list. The second command will direct them all to your merge tool (you can use merge instead of mergetool if this is your preference).

If you want to try it yourself before adding an alias, you can simply execute one of these two commands through the command line:

git ls-files -u | cut -f 2 | sort -u

git ls-files -u | cut -f 2 | sort -u | xargs git mergetool

+6
source

All Articles