我有4個分支。主要,發布,掌握,預覽。
預覽用于做實驗。我想清理預覽分支并將其與發布分支同步。
如果我只是將發布分支合并到預覽中,我仍然有舊的實驗代碼。我不知道該怎么做
uj5u.com熱心網友回復:
如果您想將實驗保留在分支中,您可以這樣做:
git checkout preview
git merge --no-commit release
# let's get the contents of files just like in release:
git restore --staged --worktree --source=release -- .
git merge --continue
現在你有一個合并release到preview,合并的內容(檔案)就像release.
另一種方式,沒有合并,但具有檔案內容的結果就像在中一樣release:
git checkout preview
git restore --staged --worktree --source=release -- .
git commit -m "Making this branch look like release, but without merging nor modifying history of this branch".
如果您希望分支release在歷史方面也一樣:
git checkout preview
git reset --hard release
# and now feel free to force-push into whatever remove branch you need to.
uj5u.com熱心網友回復:
由于您在評論中指出您對保留歷史記錄不感興趣,因此您可以簡單地洗掉分支并從您想要的任何提交中重新創建它:
git branch -D preview
git branch preview release
或作為單個命令:
git branch -f preview release
上面的兩個命令僅在分支當前未簽出時才有效。如果簽出,checkout可以使用:
git checkout -B preview release
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/536317.html
標籤:混帐分支
