Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Open merge tool without conflict

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?

like image 662
Thomas Klier Avatar asked Nov 08 '22 04:11

Thomas Klier


2 Answers

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.

like image 173
j6t Avatar answered Nov 15 '22 04:11

j6t


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

like image 22
ThorSummoner Avatar answered Nov 15 '22 05:11

ThorSummoner