git stash 常用命令用法

来源:互联网 发布:四川广电网络怎么缴费 编辑:程序博客网 时间:2024/05/29 10:05

当在一个分支的开发工作未完成,却又要切换到另外一个分支进行开发的时候,除了commit原分支的代码改动的方法外,我觉得git stash是一个更加便捷的选择。

步骤如下:

一、添加改动到stash。一般情况下git stash 就直接存储起来了。如果stash非常多,在原分支 git stash save “comment”,加入message方便后去git stash pop stash{编号}。网上很多很多资料都没有加 -a 这个option选项。git stash save -a “comment”,而对于在项目里加入了代码新文件的开发来说,-a选项才会将新加入的代码文件同时放入暂存区,与git commit -am “comment” 同理。

二、恢复改动。如果你要恢复的是最近的一次改动,git stash pop即可,如果有多次stash操作,那就通过git stash list查看stash列表,从中选择你想要pop的stash,运行命令git stash pop stash@{id}或者 git stash apply stash@{id}即可。

三、删除stash。
git stash drop

0 0