The command that finds merge conflicts is git merge
. Run git merge
, optionally with --no-commit
and optionally on a detached HEAD.
If there are conflicts, git merge
exits with a nonzero status. If there are no conflicts, git merge
exits with a zero status. If run with --no-commit
Git makes no commit in either case; if run without it, Git makes a merge commit on the current HEAD. If HEAD is detached, this commit affects only HEAD.
If you used a detached HEAD, you can now re-attach HEAD to its original branch or commit.
If you used --no-commit
, you can simply run git merge --abort
regardless of whether the merge succeeded or failed.
Hence, the simplest command sequence is to run git merge --no-commit
, save exit status, then run git merge --abort
.
Note that in all cases, Git will use the index and work-tree during the merge process, so you must make sure they are safe for Git to use for that entire period. (In particular the index and work-tree must be "clean" at the start of the process. They will be clean at the end as well, provided there are no merge drivers that leave messes behind.)
(How to get the exit status of git merge
from node.js, I have no idea.)