When I run git status
, this is what I am seeing:
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
You are in the middle of an am session.
(fix conflicts and then run "git am --continue")
(use "git am --skip" to skip this patch)
(use "git am --abort" to restore the original branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: xxx
modified: xxx
modified: xxx
Untracked files:
(use "git add <file>..." to include in what will be committed)
xxx
no changes added to commit (use "git add" and/or "git commit -a")
$ git version
git version 1.9.1
So, what' that git is trying to tell me and what's the correct way to resolve it?
I don't know if that's relevant, but we use gerrit and all changes go through review/approval process.
fix conflicts
Do a git diff
to see if you have any merge marker, like:
$ git diff hello.txt
diff --cc hello.txt
index 5eb9649,379bd44..0000000
--- a/hello.txt
+++ b/hello.txt
@@@ -1,1 -1,1 +1,7 @@@
++<<<<<<< HEAD
+Hello, master change.
++||||||| merged common ancestors
++Hello, Original.
++=======
+ Hello, branch b1 change.
++>>>>>>> b1
If not, try and reapply git am
with the -3
option: git am -3
If you have, do, for instance using kdiff3
(Windows or Linux), git mergetool --tool=kdiff3
. That will launch a graphical tool allowing you to chose between local, base and remote
+--------------------------------+
| BASE | LOCAL | REMOTE |
+--------------------------------+
| MERGED |
+--------------------------------+
With:
LOCAL
: A temporary file containing the contents of the file on the current branch.BASE
: A temporary file containing the common base for the merge.REMOTE
: A temporary file containing the contents of the file to be merged.MERGED
: The file containing the conflict markers.The git am --continue
should only be done when git status doesn't report any unstaged files.
See more with Git Conflict Resolution by Ted Felix: it has this handy summary:
- Always use "
-3
" with "git am
" to make sure you get conflict markers.- Use "
git status
" and "git diff
" to find out what went wrong.- Resolve the conflicts by any of the following methods:
- Edit each conflicting file with your favorite editor.
- "
git checkout --theirs
" or "git checkout --ours
".- "
git checkout -m
" to undo conflict resolution on specific files. (BE CAREFUL!)- "
git mergetool
" and an appropriate merge GUI tool likekdiff3
.- "
git add
" the resolved files.- "
git am --continue
" to continue the am.
With Git 2.17 (Q2 2018), don't forget to start your git am session with git am --show-current-patch
to get a better view of the path to edit in case of conflict.
See "Show current git interactive rebase operation".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With