从另一个分支变基,然后在合并另一个分支后合并到master

Rebase from another branch and then merge into master after merged the other branch

我处于这种情况:

分支 graphics 完成审核后将合并到 master 中,但现在我想将 graphics 更改也集成到我的分支 feature 中,该分支也将与完成后掌握。

所以我们必须将 feature 合并到 master 中,在 graphics 已经合并之后。

最好的方法是什么?我可以使用 graphics 更改来重新设置 feature 的基线吗?或者合并graphicsfeature(这样我会合并graphics两次吗?)?或者我必须挑选所有提交?

我希望我的情景是清楚的!

首先,将graphics合并到master。然后,在 master.

之上变基 feature
git checkout master
git merge graphics
git checkout feature
git rebase master

这样,您将获得 graphics 的更改,并且仍然在 feature 中保持整洁的历史记录。

极不建议在将 graphics 合并到 feature 之前将其合并到 master,除非您有特殊原因。

但如果您确实有特殊原因,那就继续去做吧...

git checkout feature
git merge graphics    

请注意,根据具体情况,您可能希望执行 git rebase graphics 而不是 git merge graphics。最终结果(feature 上的文件内容)将完全相同,但历史记录 a.k.a。提交树看起来会有所不同。后者将在您最终将两个分支合并到 master 时避免任何类型的额外冲突,并且看起来非常干净;我可能更喜欢那样。但是不知道你想要达到什么就很难说。

N.B。如果你执行 git rebase,然后在 graphics 上提交更多,那么你需要在最终合并到 master 之前再次执行 git rebase(我建议在之后立即执行此操作您将 graphics 合并到 master).

场景一, 当 graphics 合并到 master 时; 在这种情况下,您可以将 feature 分支从 master 变基,因为 graphics 分支更改在 master.

场景二, 当 graphics 分支尚未合并并且您需要更改时; 在这种情况下有两种可能性, 一世。将 graphics 分支合并到您的 feature 分支,只需将 graphics 分支拉入 feature 分支,然后说您在功能分支中 git pull origin graphics.

二。对 graphics 分支做 rebase 你的 feature 分支,假设你是做 git rebase featuregit rebase --continue 的功能分支,除非所有变基冲突和合并冲突都已解决。

最好的办法是用 graphics 分支重新设置分支,然后让 graphics 分支合并到 master,然后再次向主分支创建拉取请求。这会很棒。