5

I have problems with a merge, but git doesn't mark the file as conflicted. When I try to open the file with git mergetool, git just says: No files need merging.

How can I open a file without merge conflict in a three way compare?

Thomas Klier
  • 449
  • 4
  • 16

3 Answers3

3

You can do the following:

git merge --no-commit topic
git checkout --merge that_file
git mergetool that_file
git commit

That is, you avoid that the successful merge creates a commit, then you pretend that there was a conflict in that_file, then you can treat the file with git mergetool. Finally, you commit the result.

j6t
  • 9,150
  • 1
  • 15
  • 35
  • Is there a way to do this without `git checkout` clobbering changes made to the file? E.g. during a merge I want to open a 3 panel diff again to help fix build errors. – jozxyqk Dec 09 '20 at 20:19
  • @jozxyqk Not that I know of. You would have to extract the base and remote versions manually from the index, which is a PITA when the worktree version must stay unchanged. See the ThorSummoner's answer to see what it takes. You're better off when you don't close the mergetool until your build succeeds. – j6t Dec 10 '20 at 07:33
2

sadly I coudln't reproduce @Filp Stefanov's success, so I did it the hard way by hand

(from the repository root)

git merge --no-ff --no-commit <topic>
git show HEAD:<file> > <file>.ours
git show MERGE_HEAD:<file> > <file>.theirs
$(git config merge.tool) <file>.ours <file> <file>.theirs
rm <file>.ours <file>.theirs
git add <file>
git commit

said outloud thats,

  1. show our version of the file to stdout and save that somewhere
  2. show their of the file to stdout and save that somewhere
  3. open the merge tool of ours, current, theirs
  4. do your merge
  5. delete the .ours/.theirs files
  6. add & commit the merged file

I wouldn't be surprised if that's basically what git does natively

ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
-2

git mergetool uses tool specified in .gitconfig [merge] section
git mergetool --tool-help

Checkout this topic

Configure one of those as git diff tool
For example:

git config --global diff.tool kdiff3

But as i know git diff can do only 2-way diff.
Solution is to checkout 3 different directories and run kdiff3

Community
  • 1
  • 1
Filip Stefanov
  • 800
  • 3
  • 10
  • 18
  • Again: How can I open a file without merge conflict in a three way compare? Do you want me to copy all four version of the file from different commits to some location in the file system and open them manually with a merge tool? – Thomas Klier Dec 13 '16 at 09:15