储藏

当你正在做一项复杂的工作时,发现了一个和当前工作不相关但是又很讨厌的 bug。你这时想先修复 bug 再做手头的工作, 那么就可以用 git stash 来保存当前的工作状态,等你修复完 bug 后,执行‘反储藏’(unstash)操作就可以回到之前的工作里。

$ git stash "work in progress for foo feature"

上面这条命令会保存你的本地修改到储藏(stash)中,然后将你的工作目录和索引里的内容全部重置,回到你当前所在分支的上次提交时的状态。

好了, 你现在就可以开始你的修复工作了。

... edit and test ...
$ git commit -a -m "blorpl: typofix"

当你修复完 bug 后,你可以用git stash apply来回复到以前的工作状态。

$ git stash apply

储藏队列

你也可多次使用git stash命令,每执行一次就会把针对当前修改的‘储藏’(stash)添加到储藏队列中。用git stash list命令可以查看你保存的‘储藏’(stashes):

$>git stash list
stash@{0}: WIP on book: 51bea1d... fixed images
stash@{1}: WIP on master: 9705ae6... changed the browse code to the official repo

可以用类似git stash apply stash@{1}的命令来使用在队列中的任意一个‘储藏’(stashes)。 git stash clear则是用来清空这个队列。

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3