git stash

当在本地开发一段时间后,突然有了变动,比如想修复一个bug,但是本地新开发的代码不想上传,为了保持线上稳定性。这是,用stash 暂存当前工作,回到git库上最近一次的提交,等完成动作后,再恢复到开发时的状态,继续工作。

首先,添加所有当前以开发的变动:git add  .

然后保存改动,并跳到最后一次提交:git stash

则当前状态会最近一次提交,完成工作如修复bug,

用命令:git stash apply

恢复到保存的开发状态,继续工作。

git stash pop恢复栈中第一个,也可。

多次stash后,记不清了,可用 git stash list 查看所有的保存版本

git stash apply stash@{1}找回栈中第2个,

git stash drop <id>删除一个stash

git stash clear 清空

多次使用’git stash’命令后git stash list’命令将当前的Git栈信息打印出来,找版本号,例如使用’git stash apply stash@{1}’就可以将stash@{1}恢复

git stash          # save uncommitted changes
# pull, edit, etc.
git stash list     # list stashed changes in this git
git show stash@{0} # see the last stash 
git stash pop      # apply last stash and remove it from the list

git stash --help   # for more info
 
 
原理性文章:http://www.cppblog.com/deercoder/archive/2011/11/13/160007.html
原文地址:https://www.cnblogs.com/cl1024cl/p/6205564.html