A git merge
that has stopped due to conflicts leaves two1 files with information about what is being merged:
.git/MERGE_HEAD
.git/MERGE_MSG
(replace .git
with the output of git rev-parse --git-dir
if needed, e.g., if you're in a sub-directory within the git directory). The contents of MERGE_HEAD
is the other SHA-1, even if you're merging a branch by name;2 but the contents of MERGE_MSG
contains the branch name if there is one. For instance:
$ git merge --no-commit origin/master
Automatic merge went well; stopped before committing as requested
$ cat .git/MERGE_HEAD
d1574b852963482d4b482992ad6343691082412f
$ cat .git/MERGE_MSG
Merge remote-tracking branch 'origin/master'
(我不得不使用--no-commit
这里因为没有冲突)。
(如果两个文件中都没有分支名称,但MERGE_HEAD
文件的 SHA-1 与某些现有的分支提示相匹配,这将是适合许多或大多数用途的分支名称。如果它匹配多个分支提示 - 即,如果单个提交是多个当前分支名称的提示 - 其中任何一个都可能是合适的。)
1There's a third file, .git/MERGE_MODE
, which tells git that you're in the middle of a merge in the first place. It's often empty, though.
2You can merge by raw SHA-1, or any other way to specify a commit. There's no requirement that the merge be from another branch. For that matter, you can be in "detached HEAD" mode when making a new merge commit as well, so there's no requirement that the merge be into a named branch.