[英]How do I change the git branch from which I branched?
我正在開發一個功能分支,我做了一個git checkout -b feature/other-feature
,做了一些工作,提交了它,然后將它推送到github上的原始功能/其他功能。
當我從github上的other-feature分支創建了一個pull請求時,我意識到它顯示了來自原始功能分支的一組提交 - 應該合理地提交從原始分支開發的提交。
我認為我做錯了是在我執行git checkout -b feature/other-feature
之前省略了git checkout develop
,所以我認為我想要糾正這種情況的是rebase other-feature到develop。
但鑒於我把我的錯誤推到了原點並且其他人都有這個回購的克隆,我是否需要改變或做其他事情?
是的,您需要重新設置feature/other-feature
副本。 但是,在這種情況下,簡單的git rebase develop
可能不會起作用,因為你分支了另一個功能分支,而不是直接develop
。 你需要使用rebase --onto
:
git rebase --onto develop feature/earlier-feature feature/other-feature
這里, feature/earlier-feature
是你在原來的git checkout -b feature/other-feature
死掉時檢出的功能分支。
這個rebase將:
feature/other-feature
提交不在 feature/earlier-feature
的提交。 develop
。 您最終應該使用已更改的分支feature/other-feature
,該功能現在基於develop
。
筆記
rebase --onto
背后的概念以及rebase --onto
的意義。 請參見第3.6章, Git分支 - 重新定位 。 如果其他人克隆了您的存儲庫
你寫
但鑒於我把我的錯誤推到了原點並且其他人都有這個回購的克隆,我是否需要改變或做其他事情?
您仍然可以如上所述進行rebase。 但是,您不能以舊名稱強制推送已重新分支的分支。 而是創建分支的副本:
git checkout -b feature/other-feature-2 feature/other-feature
這將創建一個新的分支feature/other-feature-2
,它是feature/other-feature
的精確副本。 然后,您可以重新綁定新分支,並以新名稱推送它。 然后告訴大家feature/other-feature
已被feature/other-feature-2
取代,並刪除GitHub上的feature/other-feature
。 告訴每個人的是你為變基所支付的價格:-)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.