在branch b1使用暫存檔案和未暫存檔案時,我創建了一個新分支 ( backup-changes) 并提交了這些檔案。
// Create the backup branch from the branch you are on
$ git checkout -b backup-changes
// make sure it is created and you are on the backup branch
$ git branch -a
// check status and add and commit to the backup branch just created
$ git status
$ git add .
$ git commit
// do a dry run to see things what are things going to be
$ git push -u origin backup-changes --dry-run
// push to remote
$ git push -u origin backup-changes
我不想把它藏起來,因為我想在遠程服務器上進行備份。
現在,我切換回branch b1, 并希望恢復所有已暫存和未暫存的檔案,就像它們在我切換到 " backup-changes" 并提交之前一樣?那可能嗎?
uj5u.com熱心網友回復:
我無法理解Git 世界中備份的用處。但是有兩種可能的方法:
第一種可能性是git cherry-pick <commit-id>在目標分支 ( branch b1)。僅當您了解櫻桃采摘的行為時才這樣做!
第二種方法是分支中git reset的最后一次提交backup-changes:
git reset --soft HEAD~1
然后使用以下命令保存重置的檔案git stash:
git stash save "get back all the staged and unstaged files"
現在您可以將分支改回來:
git checkout b1
然后使隱藏的檔案生效:
git stash pop
這將洗掉stash,如果您想將 stash 保留在stash -list 中,請僅執行git stash apply此操作,并且 stash 會進一步保存并顯示為git stash list. 有關更多資訊,請參閱git stash檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/485398.html
標籤:混帐
上一篇:git分支不顯示所有分支
下一篇:從gitcli注銷
