Git還提供了一個stash功能,可以把當前工作現場“儲藏”起來,等以后恢復現場后繼續工作
正在dev分支修改 工作區有內容( hellodev.txt)
Paste_Image.png
git add hellodev.txt
Paste_Image.png
保存/隱藏工作區
git stash
Paste_Image.png
切回master分支并創建issue分支修復bug
git checkout master
git checkout -b issue-101
vi hellogit.txt
git add hellogit.txt
git commit -m "fix bug"
切回master并合并
git checkout master
git merge --no-ff -m "merge bug fix 101" issue-101
git branch -d issue-101
切回dev分支
git checkout dev
git stash list
Paste_Image.png
git stash apply恢復,但是恢復后,stash內容并不刪除,你需要用git stash drop來刪除;
git stash pop,恢復的同時把stash內容也刪了:
git stash pop
Paste_Image.png
再用git stash list查看,就看不到任何stash內容了:
git stash list
你可以多次stash,恢復的時候,先用git stash list查看,然后恢復指定的stash,用命令:
$ git stash apply stash@{0}