我main推了一個分支。然后我B從一個舊的提交創建了一個分支main,現在我想main和這個B分支一樣。
我的情況:
* B branch
|
*
|
* * C branch
| |
* * main
| |
* * [commit-x]
| /
*
|
我想要這個:
* main
|
*
|
* * C branch
| |
* *
| |
* * [commit-x]
| /
*
|
我嘗試合并B,main但這樣做我也得到了一些commit-x我不想要的來自 main (example) 的提交:
我需要幫助。
非常感謝你
uj5u.com熱心網友回復:
我質疑你是否想這樣做,因為通常重寫共享分支main是不受歡迎的。話雖如此,要回答您的問題,這就像更改main指向一樣簡單B。(注意B可以是分支名稱或提交 ID 哈希。)
git switch main
git reset --hard B
git push --force-with-lease
這是可行的,因為分支只是指向提交 ID 的“書簽”或“指標”。該reset命令用于更改分支指向的提交。
如果您不想重寫main分支,另一種選擇是提交revert您main不想要的。所以你可以這樣做:
git switch main
git revert commit-X # this is the commit ID you wish to undo.
git merge B
現在commit-X仍將成為歷史,但變化將消失。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/472762.html
標籤:混帐
上一篇:如何推送到另一個上游
