我有一個本地提交A并且我使用了git pull --rebase origin master,所以現在A堆疊在最新的遠程 master 提交之上,但我意識到我不想這樣做,并且需要實際重新基于 master 的早期愿景。
earlier_commit_hash我找到了與先前提交相關聯的提交哈希并做了git pull --rebase origin earlier_commit_hash,但似乎沒有改變任何東西(我的本地分支仍然包括所有遠程主提交之后earlier_commit_hash)。
完成我需要的正確方法是什么?
uj5u.com熱心網友回復:
來自 master 的較新提交已經是您本地歷史的一部分,這就是為什么當您rebase在較舊的提交上使用它們時它們將被繼承。請注意,它們可能仍會被新的哈希重寫,這會使情況變得更糟。
你可以試試rebase --onto。從手冊頁:
A range of commits could also be removed with rebase. If we have the following situation:
E---F---G---H---I---J topicA
then the command
git rebase --onto topicA~5 topicA~3 topicA
would result in the removal of commits F and G:
E---H'---I'---J' topicA
This is useful if F and G were flawed in some way, or should not be part of topicA.
因此,您可以使用相同的機制來準確洗掉 master 上的參考和您的分支專有提交之間的所有提交。
uj5u.com熱心網友回復:
如果我在你的位置并且我的分支在你的州,我會使用ypnos 的rebase --onto答案。這是因為它可能是最有效的單線,我很樂意這樣做。
話雖如此,您可以做的另一件事在概念上可能更簡單一些,即查看您的reflog,找到您的分支在變基之前所在的提交,然后將您的分支恢復到變基之前的狀態:
git reset --hard <previous-commit-id>
現在,就好像您沒有進行第一次 rebase,您可以繼續使用您最初打算使用的提交 ID 重做它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/456759.html
