[英]Git Rebase introducing a merge commit
我有以下情況:
CommitInitialA
CommitB1
<- CommitB2
CommitA1
<- CommitA2
CommitInitialA
<- CommitA1
<- CommitA2
<- CommitB1
<- CommitB2
CommitB3
,同時分支 A 獲得新的提交CommitA3
此時,當我嘗試在分支 A 上再次重新設置分支 B 時,我看到分支 B 中有來自CommitInitialA
的合並提交,而不是線性歷史記錄。
我應該如何第二次使用 rebase 以便我不會得到合並提交而是線性歷史記錄?
基本上在上述第 6 步之后的第二次變基之后,我想要CommitInitialA
<- CommitA1
<- CommitA2
<- CommitA3
<- CommitB1
<- CommitB2
<- CommitB3
你可以試試這個,如果沒有沖突,看看沒有問題:
git init
git checkout -b branchA
touch inita testb1 testb2 testb3 testa1 testa2 testa3
git add inita
git commit -m "commitInitialA"
git checkout -b branchB
git add testb1
git commit -m "commitB1"
git add testb2
git commit -m "commitB2"
git checkout branchA
git add testa1
git commit -m "commitA1"
git add testa2
git commit -m "commitA2"
這一點 :
第一次變基:
git checkout branchB
git rebase branchA
其他提交:
git add testb3
git commit -m "commitB3"
git checkout branchA
git add testa3
git commit -m "commitA3"
這一點 :
第二個變基:
git checkout branchB
git rebase branchA
假設A
是主分支,而B
是第一次從分支A
創建的,兩者都具有相同的提交 ID 假設
A = `CommitA1`
B = `CommitB1`
現在,兩個分支都發生了變化,所以兩個分支都有一個提交
A 移至CommitA2
,B 移至CommitB2
在將 B 分支合並到 A 分支之前,我們需要使用最新拉入分支 B 來重新設置 A 分支
所以 B 分支將有以下提交行
CommitB2 - your recent commit of branch B on the top
CommitB1 - from current brnanch B2
CommitA2 -from branch A
CommitA1 - from branch A
現在,如果您不將 B 分支合並到 A 分支並繼續處理該分支
B 分支將移動到另一個具有哈希 ID CommitB3
的提交 A 也有一些像CommitA3
這樣的CommitA3
B 在分支 A 添加之前已經有提交,因此由於分支 B 中的提交代碼重復,git pull 將嘗試合並該提交,以解決該問題。
當您再次變基時,它會顯示類似的消息
並且分別有 2 個和 2 個不同的提交
在分支 B 上,而不是采取pull
,您需要將您的提交強制推送到您的分支, git pull
為您提供由於在變基之前已經在分支 B 中的提交,可能會有合並提交的更改。
git push --force
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.