如何将合并和还原的PR提交到新的PR中?

时间:2014-10-14 15:44:34

标签: git github merge pull-request

长话短说,我处于以下情况:

创建了一个功能分支,工作了一段时间,收集了大约30个提交,并合并到master。然后通过GitHub的网络界面恢复合并(通过创建一个新的PR来恢复旧的效果)。

现在,我已经修复了导致我们恢复合并的问题,并且我想创建一个新的PR,其中包含来自原始PR的所有30个左右的提交以及另外两个来自我的PR固定。

我的功能修复分支基于功能分支的(未合并的)负责人,提交了几次,然后推动创建公关 - 但由于某种原因,公关只会选择新提交,而不是旧提交。

如何在新PR中包含旧提交?

我可以快速访问回购(我们正在使用shared repo model),因此几乎所有不需要强制推送到master的操作都可以。

简化的git历史记录:

* [feature-fix]  <-- This is the branch I want to pull from now
| * [master]
| * [merge revert PR]
* |\
| | * [revert PR]
* |/              <-- This is the first commit included in the new PR by github
| * [merge PR]
|/|
* | [feature]  <-- This is where the original PR came from
| |
* |   <-- I want these commits, originally included in the old PR, to be included
* |       in my new PR too.
| |
* | <-- Started work on feature here. This is the first commit I want to include.
 \|
  * <-- Common ancestor between `feature-fix` and `master`, as far as I can see

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您需要执行以下操作。

git checkout master
git revert SHA_OF_MERGE_REVERT_PR
git merge feature-fix 

关键步骤是恢复还原合并的提交。 SHA删除了所有更改,但保留了所有合并历史记录,这就是您只看到新提交的原因。

您可以从Linus自己here

了解更多相关信息