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.
2. Use "git status
" and "git diff
" to find out what went wrong.
3. 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 like kdiff3
.
- "
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".
Also, before Git 2.36 (Q2 2022), "git am
"(man) can read from the standard input when no mailbox is given on the command line, but the end-user gets no indication when it happens, making Git appear stuck.
See commit 7b20af6 (03 Mar 2022) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit 1b54f5b, 04 Apr 2022)
am/apply
: warn if we end up reading patches from terminal
In an interactive session, "git am
"(man) without arguments, or even worse, "git am --whitespace
"(man) file, waits silently for the user to feed the patches from the standard input (presumably by typing or copy-pasting).
Give a feedback message to the user when this happens, as it is unlikely that the user meant to do so.
You will now see:
reading patches from stdin/tty...