git tells me that I Merge conflict, but also tells me that no files need merging
Asked Answered
S

3

13

I committed some changes in the branch new.

I checkout 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 config files and when I tried to use mergetools I got:

$ git mergetool kdiff3
No files need merging

I ran a diff and it outputted 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 as to how to solve this, I want to solve this in the simplest manner possible, I don't really care if I lose the information from the branch new, but I want to understand what went wrong and why I can't use the merge tools.

It just seem weird to me that I have a merge conflict but no files need to be merged.

Standfast answered 29/3, 2013 at 16:17 Comment(1)
Possible duplicate of git mergetool reports "No files need merging"Howlet
C
5

I think your mergetool command is wrong. Should be

$ git mergetool

Or

$ git mergetool --tool=kdiff3

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

More Info: https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

Crawley answered 29/3, 2013 at 16:45 Comment(0)
S
15

I tried

git mergetool .

Seemed to work.

Stamp answered 15/2, 2017 at 22:19 Comment(1)
@scorpiodawg I assume this works because it explicitly tells git to open the mergetool on all files that need merging (atleast, under the current directory)Stamp
A
9

I had this issue even when just running the correct command:

$ git mergetool

It may have something to do with having rerere turned on (see this link [Ed.: link no longer working])

I resolved the issue by creating two aliases in .gitconfig, which kick off mergetool for each conflicted 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;dr By request, here's a brief explanation of what this does:

  • git ls-files -u: after a merge attempt with conflicts, this lists all unmerged files, along with some extraneous information and repetition; if run right after a merge, this is essentially all the files with conflicts
  • | cut -f 2 cuts out the 2nd field of this output, which is essentially the file path
  • | sort -u eliminates duplicates
  • | xargs git mergetool pipes this list of files into the mergetool command, which launches your GUI merge tool (assuming you have one set up)

So you can run the first command if you just want to see the files listed. The second command will pipe those all into your merge tool (you could use merge instead of mergetool if that's your preference).

If you want to try it out on your own before adding an alias, you could just run one of these two commands via the command line:

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

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

Asperity answered 25/3, 2014 at 15:29 Comment(5)
YES! I wonder why no upvotes, We can't be the only ones using rerere!Those
Can you explain more of what this does? i am running into this issue and basically cannot merge my files at all...Orchestrate
@Chrisgozd, added an explanation to the answerAsperity
Why this complication for something so basic??Prager
@ haelix this was the only way I could figure out how to do it. I would suggest trying @ThorSummoner's answer first, but the method I described was the simplest approach that worked in all cases for m.Asperity
C
5

I think your mergetool command is wrong. Should be

$ git mergetool

Or

$ git mergetool --tool=kdiff3

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

More Info: https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

Crawley answered 29/3, 2013 at 16:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.