git新手常見錯誤01

錯誤信息:

error: Your local changes to the following files would be overwritten by checkout:
        .idea/workspace.xml
Please commit your changes or stash them before you switch branches.
Aborting

中文釋義:

請在切換分支之前提交您的更改或存儲他們

發生場景:

比如:git在當前分支沒有提交的情況下切換到其他分支

解決方案:

1、提交當前變更

git commit -m “the commit message"

2、存儲當前變更

git stash
Saved working directory and index state WIP on 20190613: baf3c3a

在當前分支上執行  $ git stash 命令。將當前分支存起來,id爲 baf3c3a

這樣就可以切換分支了

可以使用$ git stash list  命令去查看我們“存儲”的列表

3、恢復存儲的項目

一、用 $ git stash apply 命令恢復,但是恢復後,stash內容並不刪除,這時候再執行  $ git stash list 命令,id 爲  baf3c3a 的儲藏項目還會在列表中,你需要用 $ git stash drop 來刪除;


注意: 如果有一個分支上多個 stash,如果需要恢復指定的 stash ,可以在命令尾部加id,如  $ git stash apply stash@{0},同樣刪除指定 stash 項目則執行如 $ git stash drop stash@{1}  。


二、用  $ git stash pop  命令,恢復的同時把 stash 存儲列表的內容也刪了。這時候再執行  $ git stash list 命令,id 爲  8528ea2 s 的儲藏項目不會在列表中。
參考鏈接:https://blog.csdn.net/asheandwine/article/details/79003270

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章