git mergetool
is a shell script (/bin/sh; /bin/bash can run it, if you have only bash and not plain old sh). It:
- Extracts the three files from the index (
.BASE
= stage 1 entry, .LOCAL
= stage 2 entry, .REMOTE
= stage 3 entry). The fourth file is used as a check on the merge tool—there's no need for this if you are going to do your merge manually.
- Runs your selected merge tool, using a second shell script.
- Depending on the tool and its exit status, asks you if the merge succeeded, or uses the exit status to decide if the merge succeeded. If you say it did, it runs
git add
on the merged file.
- Removes the files it created in step 1.
It does this in a loop, for all unmerged files.
Your job is to modify that shell script so that it extracts the three files and leaves them, i.e., to do (most of) step 1 and then not do the remaining steps at all. Simply find the script—it's in $(git --exec-path)/git-mergetool
—and copy it somewhere else under another name, e.g., git-extract-unmerged
, modify it to behave the way you want, and then run git extract-unmerged
and you will have those .BASE
, .LOCAL
, and .REMOTE
files that you want.
(Or you could set merge.conflictStyle
to diff3
and not bother with all of the above, now that the work-tree file has all the information you need. That's what I do instead.)