git commit --file .git/MERGE_MSG
as already mentioned is fine but it ignores a few points:
- The current directory is not the top-most directory
- The current repository is a Git submodule thus having no the
.git
directory but a file .git
.
And optionally:
MERGE_MSG
contains some information about files with conflicts.
The first two points can be used with git rev-parse
:
git commit -F "$(git rev-parse --git-dir)/MERGE_MSG"
Or, alternatively, with a Git alias:
commit-merge = !cat $(git rev-parse --git-dir)/MERGE_MSG | git commit -F -
This works both in "normal" repositories and submodules. If the #
-marked conflict markers should be discarded, for simplicity, only the first line for the merge message could be taken:
git commit -m $(head -1 $(git rev-parse --git-dir)/MERGE_MSG)
Or another alias:
commit-merge = !head -1 $(git rev-parse --git-dir)/MERGE_MSG | git commit -F -
I had to use the -F
key in aliases because I couldn't make Git emit quotes to be processed in the generated commands with bash (otherwise git commit
would complain for partial commits during merges).
Git 2.12.0 that was released two days ago introduces git merge --continue
to make a merge commit that was stopped on conflicts during the merge. It works fine for submodules as well, but does not accept --no-edit
, at least yet, so an editor is suggested to change the commit message before concluding the merge.