Git 由于提交被放弃而合并挂起

Git merge pending due to an abandoned commit

我有两个提交。提交 B 依赖于提交 A。提交 A 已被放弃。现在我在合并 B 时遇到错误。它说已提交,由于 B 对 A 的依赖而合并待处理。

我用谷歌搜索但找不到确切答案。我需要一步一步的解决方案,因为我是 git 的新手,并且很难理解如何解决这个问题。

事情是这样的。

  1. git 在本地提交 A.

  2. git 远程推送 A。

  3. A 被放弃了,但是我的本地 git 已经提交了 A。

  4. git 在同一分支中为 B 在本地提交(使 B 依赖于 A)。

  5. git 在同一分支中将 B 推送到远程。

  6. 现在 B 没有合并,因为 A 被放弃了。

我需要合并 B 并且我希望删除对 A 的依赖。希望现在清楚了!

这是服务器错误:

Change 1184 - Submitted, Merge Pending

在评论中:

Gerrit Code Review

Change could not be merged because of a missing dependency. The following changes must also be submitted: (commit-id, which was abandoned)

rebase 有用吗?如果可以,怎么做?

Here 和你的问题一样。

If committ B has a dependency on A, then B cannot be merged until A is merged. Since you have abandoned A, Gerrit will not automatically merge B.

What you will need to do is modify B (perhaps using git rebase) so that it no longer depends on A, and resubmit the change to Gerrit.

如何变基/合并它?

git-review -d 1184 
git rebase origin/master
git status
<edit "both modified" files in status report>
git add <files>
git rebase --continue
git review

查找有关此类问题的更多有用信息here

有多种方法可以解决您的问题。选择你觉得最舒服的那个。

这是一个:

  1. git checkout yourbranch(确保你在正确的分支上)
  2. git reset --hard A^(将所有内容重置为 A 之前的提交)
  3. git cherry-pick B(其中 B 是您要保留的提交的哈希值)
  4. git log(确认是你想要的)
  5. git push --force(根据您平时的推送方式可能需要指定其他选项)

这是另一个,结果是等价的:

  1. git checkout yourbranch(确保你在正确的分支上)
  2. git rebase --onto A^ A(在 A 之前的提交之上重新设置 A 之后的所有内容,有效地删除 A)
  3. git log(确认是你想要的)
  4. git push --force(根据您平时的推送方式可能需要指定其他选项)

这是第三个,结果仍然相同:

  1. git checkout yourbranch(确保你在正确的分支上)
  2. git rebase --interactive A^(将打开您的编辑器)
  3. 删除显示提交 A 的行,保存并关闭
  4. git log(确认是你想要的)
  5. git push --force(根据您平时的推送方式可能需要指定其他选项)