"You are in the middle of an am session" 是什么意思?

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

当我 运行 git status 时,这就是我所看到的:

$ 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

那么,git 想告诉我什么,解决它的正确方法是什么?

我不知道这是否相关,但我们使用 并且所有更改都经过 review/approval 流程。

发生的事情是工作树中的某些文件已更改,并在 AM 会话开始之前提交(AM 是一种从电子邮件中应用补丁的方法,其中电子邮件被拆分为更改和作者信息,然后作为补丁应用到存储库)。

这与您更改文件、提交它,然后尝试根据旧版本在同一行中合并同一文件中的更改相同。 Git 根本不知道哪个版本的更改有效,因此最终处于 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)

有多种方法可以解决此类冲突,并且都是手动的。您需要一些 3 向合并工具(可以 google 用于它),它允许您比较更改并选择您想要保留的那个。 vim 编辑器 AFAIK 嵌入了此工具,但我从未使用过它。

还有一些图形工具可让您解决 SourceTree 或类似软件中的冲突,但这完全取决于存储库的位置以及这些图形工具是否可用。

UPD:您还可以通过执行消息中所写的 git am --abort 来恢复此 AM 会话更改。这会将分支恢复到 AM 会话开始之前的状态,有效地丢失补丁信息。

fix conflicts

做一个git diff看看你是否有任何合并标记,比如:

$ 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

如果不是,请尝试使用 -3 选项重新应用 git amgit am -3

如果有,请执行,例如使用 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             |
+--------------------------------+

有:

  • LOCAL: 包含当前分支上文件内容的临时文件。
  • BASE: 包含合并公共基础的临时文件。
  • REMOTE: 包含要合并的文件内容的临时文件。
  • MERGED: 包含冲突标记的文件。

仅当 git 状态未报告任何未暂存的文件时才应执行 git am --continue

使用 Git Conflict Resolution by Ted Felix 查看更多:它有这个方便的摘要:

  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:
  • 使用您喜欢的编辑器编辑每个冲突文件。
  • "git checkout --theirs" 或 "git checkout --ours".
  • "git checkout -m" 撤销对特定文件的冲突解决。 (小心!)
  • "git mergetool" 和合适的合并 GUI 工具,如 kdiff3.
  1. "git add" 已解析的文件。
  2. "git am --continue" 继续上午。

使用 Git 2.17(2018 年第 2 季度),不要忘记使用 git am --show-current-patch 开始您的 git am 会话,以便更好地查看要编辑的路径,以防万一冲突。
参见“Show current git interactive rebase operation”。


此外,在Git 2.36 (Q2 2022)之前,"git am"(man)可以在命令行没有给出邮箱的情况下从标准输入中读取,但是结束-当它发生时,用户没有得到任何指示,使 Git 出现卡住。

参见 commit 7b20af6 (03 Mar 2022) by Junio C Hamano (gitster)
(由 Junio C Hamano -- gitster -- in commit 1b54f5b 合并,2022 年 4 月 4 日)

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.

您现在将看到:

reading patches from stdin/tty...

让我们一一看看它们的含义...

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

这意味着您在本地提交了一些内容,但尚未与源同步。

本地:您在计算机中克隆并开始处理的存储库。

origin : 主存储库 from 每个人都可以克隆。

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)

您在制作补丁的过程中遇到了冲突,您必须将这些东西恢复到原始状态(使用 git am --abort)或按照以下步骤解决冲突。

  1. 类型 git status
  2. 检查状态,如果您看到文件名显示 (both modified)

  3. 打开那些文件,解决保留你想要的和丢弃你不需要的的冲突。

  4. 现在通过键入 git add file1 file2

  5. 添加您解决冲突的文件
  6. 现在是时候继续 session

  7. 类型git am --continue

如果您想跳过此补丁类型

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")

所以这里 git 试图通知您自上次提交以来更改的文件。那些是旧文件,你只是在这里和那里改变了一些东西,里面会显示为修改过的。

您在 未跟踪文件 下看到的是那些之前 git 不知道的文件,因为它们是新文件。

Steps to resolve this step

1.) 对于未跟踪的文件

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

2.) 将添加的文件提交到存储库

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

备注

正如您所提到的,您也在使用审查系统 (gerrit)。您可能只想向现有提交添加新补丁而不是新提交。如果是这种情况,您需要这样做

git commit --amend

3.) 现在是推送代码的时候了(如果你愿意的话)

git push

对于 gerrit 这样做

git push review