You can solve this outside of git mergetool
: run git status --porcelain
to get a list of all unmerged files and their states in machine-readable format.
If your Git is new enough, it will support --porcelain=v2
. See the git status
documentation for details on the output formats. Output format v2
is generally superior for all purposes, but you should be able to make do with either one.
Next, you must write a program. Unfortunately Git has no supplied programs for this. Your program can be fairly simple depending on the specific cases you want to solve, and you can use shell scripting (sh or bash) as the programming language, to keep it easy.
Since you're concerned about the cases where git mergetool
says:
Use (m)odified or (d)eleted file, or (a)bort?
you are interested in those cases where the file name is missing in the stage 1 ("base") version and also missing in the stage 2 ("local") version, but exists in the stage 3 ("remote") version. (See the git status
documentation again and look at examples of your git status --porcelain=v2
output to see how to detect these cases. Two of the three modes will be zero.) For those particular path names, simply run git add
on the path name to mark the file as resolved in favor of the created file.
Once you have marked all such files, you can go back to running git mergetool
to resolve additional conflicts, if there are any.
Note that your "program" can consist of running:
git status --porcelain=v2 > /tmp/commands.sh
and then editing /tmp/commands.sh
to delete all but the lines containing files that you want to git add
. Then change all of those lines to read git add <filename>
where <filename>
is the name of the file. Exit the editor and run sh /tmp/commands.sh
to execute all the git add
commands. That's your program!