Running git merge will start your preferred editor1 if and only if all of the following conditions hold:
- The merge starts successfully (i.e., the index is not in a bad state, and the arguments to
git merge were all parsed successfully).
- Git found or made a merge base. Older versions of Git will use the empty tree as a merge base for unrelated histories; newer ones require
--allow-unrelated-histories.
- The merge base thus found is not the current (HEAD) commit, or you used
--no-ff.
- The other commit you passed to
git merge is not already an ancestor of the current commit. (For octopus merges, the rules are a little more complicated, but the difference should be clear enough: there is more than one "other commit".)
- The merge succeeded without conflicts, or all conflicts were low-level conflicts resolved via an eXtended-strategy-option (
-X ours or -X theirs). (Note that the -s ours strategy never has conflicts, making this constraint vacuous there.)
- You did not pass a
-m and merge message argument (or you did but added --edit as well; see commentary below this answer).
- You did not specify
--no-commit (the editor is invoked due to the merge commit being made!).
You can therefore guarantee that Git won't run your preferred editor by passing a merge message via -m. Alternatively, you can deliberately not pass a merge message but provide an environment GIT_EDITOR setting that invokes something other than an actual editor. For instance:
GIT_EDITOR=true git merge --quiet $hash
will run the merge to completion without opening an editor, or will fail because the merge itself stopped with conflicts, or never started in the first place. And, as Daniel H noted in comments below, --no-commit suppresses the final commit, hence suppresses the editor.
Besides these techniques, it's possible to invoke git merge-recursive directly. The git stash script does so. Be careful with this trick since it bypasses a lot of the usual safety checks.
1Your preferred editor is defined by the first of these various settings:
$GIT_EDITOR in the environment
core.editor as configured through git config
- the compiled-in default editor
Using git var GIT_EDITOR will tell you which editor you have chosen, or defaulted-to.