幾個月前,我對我的代碼進行了大量更改并將其推送到 master 中。
現在我需要洗掉我所做的所有更改,并將分支的初始狀態推回 master。
我對所有命令感到困惑,不想弄亂我的 git,我怎樣才能將分支重置為他的初始狀態?
uj5u.com熱心網友回復:
在新的日子里,您可以像以前的修訂版(或者實際上,任何修訂版......甚至來自其他分支)一樣獲得作業樹restore:
git restore --staged --worktree --source=<the-revision> -- .
然后,您可以提交任何您認為有意義的內容:
git add . # maybe this is not needed because I used --staged, but I am not that familiar with the UI so....
git commit -m "Taking it back to how it was back then"
舊方法需要幾個步驟,但它同樣容易作業,沒有麻煩:
git checkout the-commit-with-content-I-want
git reset --soft the-branch-where-i-want-it
git commit -m "Taking it back to blahblah"
# now you have a revision past the-branch-i-want
# check that you like what you see in history with git log and stuff.... also check files contents and so on
# when you are confident, move the branch pointer:
git branch -f the-branch-where-i-want-it
git checkout the-branch-where-i-want-it
你完成了
uj5u.com熱心網友回復:
另一種將分支“重置”回某個較早狀態而不修改任何現有歷史記錄的方法是使用git apply來自 diff 的輸出:
git checkout master
git status # Should report "nothing to commit, working tree clean"
git diff HEAD initial-state-of-the-branch-commit | git apply -
git commit -m "Reset back to initial state of the branch" -m "Using command: git diff HEAD initial-state-of-the-branch-commit | git apply -"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/518322.html
標籤:混帐github
上一篇:Git結帳標簽現有分支
