在Git中保存工作目录中的更改时保存更改

有没有一个git stash命令, git stash您的更改,但保持在工作目录呢? 所以基本上是一个git stash; git stash apply git stash; git stash apply一步git stash; git stash apply

为了实现这个目标,另一种方法就是将您想要保留的更改--keep-index ,然后使用--keep-index存储所有内容:

 $ git add modified-file.txt $ git stash save --keep-index 

上面的命令将隐藏所有内容,包括modified-file.txt ,但是它也会将该文件暂存在工作目录中。

从官方的Linux Kernel Git文档中findgit stash

如果使用--keep-index选项,则已经添加到索引的所有更改都将保持不变。

git stash ,然后git stash applygit stash && git stash apply )将藏匿文件并立即应用藏匿之后。 所以毕竟你会有你的变化存储和工作目录。 你可以创build一个别名,如果你想在一块。 只要把这样的东西~/.gitconfig

 [alias] sta = "!git stash && git stash apply" 

在实际中可能会使用的答案的一个小的增强。

 $ git add modified-file.txt (OR $ git add . ---- for all modified file) $ git stash save --keep-index "Your Comment" 

有一个技巧可以帮助你,而不是隐藏的东西,但FWIW:

 git add -A git commit -m "this is what's called stashing" (create new stash commit) git tag stash (mark the commit with 'stash' tag) git reset HEAD~ (Now go back to where you've left with your working dir intact) 

所以现在你有一个提交标签隐藏在你的处置,这是不可能做一个git stash pop无论如何,但你可以做的事情,如创build补丁或重置文件等从那里,你的工作目录文件也保持完好BTW。