Reputation: 179
I use a script to manage my development process. Some times I need to know if a merge is pending.
I use to use "git ls-files --unmerged", but it does not work when conflicts has been resolved and the unmerged files added to the index.
In that case, is there a way to know if a merge is ongoing ?
Thank you.
Upvotes: 6
Views: 3033
Reputation: 42015
From a script: look if "$(git rev-parse --git-dir)"/MERGE_HEAD
exists (that is how __git_ps1
does it).
Manually, I let the repo status show in my prompt.
__git_ps1
has very useful features. Beside showing you your current branch, status, index status, remote tracking branch status on your command line prompt, it tells you if you have a merge ongoing.
You can find an instruction there.
In short, download git-prompt.sh, put it in your PATH
, source it in your ~/.bashrc
, use __git_ps1
in your PS1
in ~/.bashrc
.
Read the comment at the top of git-prompt.sh for additional features.
An example:
gauthier@sobel:~/tmp/sigrt_val (master *) $
(shows current branch master
, and that I have local changes *
)
Another example with a conflicting merge:
gauthier@sobel:~/tmp/sigrt_val (two) $ git merge one
Auto-merging test.c
CONFLICT (content): Merge conflict in test.c
Automatic merge failed; fix conflicts and then commit the result.
gauthier@sobel:~/tmp/sigrt_val (two *+|MERGING) $
(*
for local changes, +
for staged files, |MERGING
for currently in an unfinished merge)
Upvotes: 9
Reputation: 106490
If you are in the middle of a non-fast-forward merge that has conflicts, then git status
alone can inform you of your current state.
From the site:
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
If you've finished up the conflicts, you'll likely see a message like this:
$ git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
The __git_ps1
script is a wonderful visual convenience, but it's still standing on the shoulders of the standard metadata that can be found in other parts of Git.
Upvotes: 4