简体   繁体   English

分支合并到 master 后的 git rebase

[英]git rebase after branch has been merged into master

Say I have a master branch and a feature branch called FA1 that is branched off master and I have another feature branch called FA2 that is branched off FA1.假设我有一个 master 分支和一个名为 FA1 的功能分支,它从 master 分支出来,我有另一个名为 FA2 的功能分支,它从 FA1 分支出来。

When I'm working on FA2 and I want to bring changes from FA1, I do: git rebase -i FA1 .当我在 FA2 上工作并且我想从 FA1 中进行更改时,我会这样做: git rebase -i FA1

However, at some point FA1 gets merged into master and I want to change FA2 to be based off master now, it no longer makes sense that is branched off FA1.但是,在某些时候 FA1 合并到 master 中,我现在想将 FA2 更改为基于 master,从 FA1 分支不再有意义。

What is the proper approach to change the target branch of FA2 to be master OR in other words, for FA2 to be up to date with master.将 FA2 的目标分支更改为 master 或换句话说,使 FA2 与 master 保持同步的正确方法是什么。

Just do做就是了

git fetch
git rebase origin/master

Background: Git does not store anywhere which branch you rebased onto in the past, so it does not know you rebased onto FA1 previously, and as such there is noting special to do when you want to switch the base to rebase into, expcept, well to specify that new base to rebase .背景:Git 不会存储您过去重新定位到哪个分支的任何位置,因此它不知道您之前重新定位到FA1 ,因此,当您想要将基础切换到重新定位时,没有特别的事情要做,除了,好吧将新的基础指定为rebase

[...] it no longer makes sense that is branched off FA1 [...] [...] 从 FA1 分支出来不再有意义 [...]

This is not quite true.这并不完全正确。 Whether branch FA2 still exists or not, FA1 stays branched off the same commit .无论分支FA2是否仍然存在, FA1保持从同一个 commit分支出来。

If you then need to bring into FA2 recent commits merged into master , yes, you can indeed rebase FA2 on master as you did before with FA1 .如果您需要将FA2最近的提交合并到master ,是的,您确实可以像以前使用FA1一样在master FA2

Make FA2 derive directly from master :使 FA2 直接从 master 派生:

 git checkout FA2
 git rebase FA1 FA2
 git rebase --onto master FA1 FA2

see the rebase documentation查看rebase 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM