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

心已入冬 提交于 2019-11-30 16:45:36

问题


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.


回答1:


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:

  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.
  4. "git add" the resolved files.
  5. "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".




回答2:


What happened is that some file in working tree was changed, and committed prior AM session began (AM is a way to apply patches from email messages where email is split to changes and author info and then applied as a patch to repository).

This is same as if you changed file, committed it, and then tried to merge change in same file in same lines based on old version. Git simply doesn't know which version of change is valid and therefore ends up in conflict state.

These lines tell you that you have conflict:

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)

There are several ways to resolve this sort of conflicts, and all of them are manual. You need some 3-way merge tool (can google for it) that allows you to compare changes and choose the one you want to keep. vim editor AFAIK has this tool embedded, but I never used it.

There are also graphical tools allowing you to resolve conflicts in software like SourceTree or similar, but it all depends on where the repository is and whether those graphical tools are available there.

UPD: You also can revert this AM session changes by doing git am --abort which is written in the message. This will revert branch to the state before AM session started, effectively loosing the patch information.




回答3:


Let's look at their meanings one by one...

On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits)

This means that you committed something locally but have not synced it with the origin.

Local : The repository you cloned in your machine and started working on it.

origin : The main repository from where every person can clone.

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)

You were in middle of making a patch and you had conflicts , you have to either restore the things to the original state (using git am --abort) or resolve the conflicts by following these steps.

  1. Type git status
  2. Check the status , if you see file names saying (both modified)

  3. Open those files , Resolve the conflicts keeping what you want and discarding the what you don't.

  4. Now add the files you resolved the conflicts in by typing git add file1 file2

  5. Now its time to continue the session

  6. Type git am --continue

In case you want to skip doing this patch type

git am --skip

You had some changes and you were in middle of making a patch out of it. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)

modified:   xxx
modified:   xxx
modified:   xxx

Untracked files: (use "git add ..." to include in what will be committed)

xxx

no changes added to commit (use "git add" and/or "git commit -a")

So here git is trying to inform you about the files which are changed since the last commit . The ones that were old files and you just changed somethings here and there inside it will be shown as the modified .

The one you see under the untracked files are those which were unknown to git earlier because they are new files.

Steps to resolve this step

1.) For the untracked files

1.1.) git add <filename1> <filename2> and so on...

2.) Commit the added files to the repository

2.1)  git commit -m "Message of your choice"

Note

As you have mentioned you are working with a review system as well (gerrit). You might want to just add a new patch to an existing commmit rather than a new commit. If that is the case you need to do this

git commit --amend

3.) Now its time to push the code (if you want to)

git push

For gerrit do this

git push review


来源:https://stackoverflow.com/questions/28875767/what-does-you-are-in-the-middle-of-an-am-session-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!