2013-07-24 18 views

回答

67

對於它的價值,另一種方式做,這是階段,你要保留更改,然後使用--keep-index藏匿的一切:

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

的上述命令將藏匿的一切,包括modified-file.txt,但它也將離開該文件上演,並在您的工作目錄。

official Linux Kernel Git documentation for git stash

如果--keep-index選項時,已添加到索引的所有變化都保持不變。

27

git stash然後git stash applygit stash && git stash apply)將存儲文件並在其之後立即應用存儲。所以,畢竟你會有你的變化存儲和工作目錄。如果你想要一個部分,你可以創建一個別名。只要把這樣的事情~/.gitconfig

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

+1如果你告訴我如何創建一個別名 – anthropomorphic

+0

也有'git stash; git存儲應用'和'git存儲&& git存儲應用'? – anthropomorphic

+8

相信不同的是,[''&&運行僅當第一返回零狀態代碼第二命令(http://linux-training.be/files/books/html/fun/ch11s04.html)。 – madhead

2

有一個竅門可以幫助你,而不是藏起來」的事情,但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但無論如何你可以做的事情,如創建補丁或有重置文件等,您的工作目錄文件也被原封不動BTW。

3

小補的答案在實際可能會使用哪個。

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