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

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