Search code examples
gitgerrit

What does "You are in the middle of an am session" mean?


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 and all changes go through review/approval process.


Solution

  • 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             |
    +--------------------------------+
    

    http://tedfelix.com/software/git-mergetool-kdiff3.png

    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:

    1. 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.
    1. "git add" the resolved files.
    2. "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...