2013-07-24 10 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)はファイルを隠し、その直後に隠しを適用します。だから、あなたは隠し場所と仕事場にあなたの変更を加えるでしょう。エイリアスを1つにまとめることができます。ただ、~/.gitconfigにこのようなものを置く:それは価値がある何のため

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

+1あなたが別名を作成する方法を教えれば、 – anthropomorphic

+0

でも、 'git stash; git stash apply'と 'git stash && git stash apply'? – anthropomorphic

+8

違いは、 '' && 'は、最初に0のステータスコードが返された場合にのみ2番目のコマンドを実行する」(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を行うことは可能ではありませんが、あなたパッチの作成やそこからのファイルのリセットなどの作業を行うことができます。作業ディレクトリファイルもそのまま残っています。

3

実際には使用する可能性のある回答が少し増強されています。

$ git add modified-file.txt 
(OR $ git add . ---- for all modified file) 
$ git stash save --keep-index "Your Comment" 
関連する問題