git stash 可用来暂存当前正在进行的工作
比如想pull 最新代码, 又不想加新commit,
或者另外一种情况,
为了fix 一个紧急的bug, 先stash, 使返回到自己上一个commit, 改完bug之后再stash pop, 继续原来的工作。
基础命令:
$git stash
$git pull
$git stash pop
pop后有冲突就可以解决冲突
stash的好处是可以先将你的改动暂存到本地仓库中,随时可以取出来再用,但是不用担心下次push到服务器时,把不想提交的改动也push到服务器上,因为stash save(Stash Changes)的内容不参与commit和push。
原文链接:
https://blog.youkuaiyun.com/longxiaowu/article/details/26815433
https://blog.youkuaiyun.com/langgufu314/article/details/84802179
一、添加改动到stash。
在原分支 git stash save “messeag”,这条命令实际上是
git stash命令的完整版。即如果需要在保存工作进度的时候使 用指定的说明,必须使用如下格式:
git stash save “message...”
二、恢复改动。
如果你要恢复的是最近的一次改动,git stash pop
即可,我用这个用的最多。如果有多次stash操作,那就通过git stash list
查看stash列表,从中选择你想要pop的stash,运行命令git stash pop stash@{id}
或者 git stash apply stash@{id}
即可
三、删除stash。
git stash drop [<stash>]
如果不加stash编号git stash drop
,默认的就是删除最新的,也就是编号为0的那个,加编号就是删除指定编号的stash。git stash drop <stash@{id}>
清除所有stash,整个世界一下子清净了
git stash clear
git stash pop 与 git stash apply <stash@{id}> 的区别。
git stash pop 和 git stash apply 这两个命令的区别
git stash pop stash@{id}
命令会在执行后将对应的stash id 从stash list里删除
git stash apply stash@{id}
命令则会继续保存stash id。
如果不想有越来越多的陈旧stash id 仍然存在的,所以我更习惯于用git stash pop 命令