[英]Rebase from another branch and then merge into master after merged the other branch
[英]Rebase or merge a branch onto another feature branch merged in master
我正在處理一個功能分支場景,我有點不確定將 go 作為“最佳解決方案”的方式。
a -- b -- c <-- Master
\
d -- e -- f <-- Branch 1 (in review)
\
d -- e -- f -- g -- h <-- Branch 2
我開始在Branch 1
上工作,完成了完整的實現,並打開了拉取請求。 但是,我需要創建Branch 2
來啟動功能實現的第二部分。
a -- b -- c x <-- Master
\ /
d -- e -- f <-- Branch 1 (Merged in Master)
\
d -- e -- f -- g -- h <-- Branch 2
這樣, Branch 1
被 CI 合並到主分支中。 問題是Branch 2
加載了Branch 1
中的所有更改,我不知道將 Master 更改合並到我的Branch 2
中的方式。
交互式變基還是合並?
非交互式變基應該足夠了
首先,確保您的本地master
服務器與“ upstream
”/ master
服務器是最新的( upstream
是遠程引用目標存儲庫,您的 PR 已在其中合並)
git switch master
git fetch upstream
git merge upstream/master
然后重播branch1
啟動后完成的每個branch2
提交,並在更新后的master
之上重播它們。
A git merge-base branch1 branch2
應該給你提交d
of branch1
git rebase --onto master $(git merge-base branch1 branch2) branch2
這樣,你得到:
d' -- e' -- f' -- g' -- h' <-- Branch 2
/
a -- b -- c x <-- Master
\ /
d -- e -- f <-- Branch 1 (Merged in Master)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.