我們開發(fā)時,想切換到另一個分支,而當前分支的工作區(qū)的內容雜亂無章,我們并不想提交。那怎么能保存現(xiàn)場呢?git stash
當前的狀態(tài)
a 在工作區(qū),b已經(jīng)提交到了暫存區(qū)

Paste_Image.png
保存現(xiàn)場
git stash

Paste_Image.png
此時工作區(qū)和暫存區(qū)被保存了,都是干凈的:

Paste_Image.png
查看保存歷史
git stash list
每
git stash 一次就會產(chǎn)生一條記錄,所以會產(chǎn)生很多條記錄
Paste_Image.png
恢復現(xiàn)場
git stash apply 恢復最近的一次存儲,如果想恢復更早的存儲,使用名字,如:git stash apply stash@{1} 注意:0是最新的。

Paste_Image.png
發(fā)現(xiàn)怎么只是恢復了和工作區(qū)的內容,而暫存區(qū)的內容沒有恢復?我們可以使用 git stash apply --index

Paste_Image.png