1. 変更を退避する
git stash
=git stash push
# 作業ディレクトリとインデックスの変更を退避
$ git stash push
# 作業ディレクトリの変更を退避
$ git stash push -k
# 作業ディレクトリとインデックスの変更 + 新規作成ファイルを退避
$ git stash push -u
# 作業ディレクトリとインデックスの変更 + 新規作成ファイル + ignoredファイルを退避
$ git stash push -a
# メッセージ付きでstashする $ git stash push -m "message"
2. 退避した変更を確認する
# stashを一覧表示する
$ git stash list
# 特定のstashを表示する $ git stash show # stash@{0}を指定したのと同じ $ git stash show stash@{1}
# 特定のstashの差分を表示する $ git stash show -p stash@{1}
3. 退避した変更を再適用する
# 特定のstashを再適用する(stashは削除されない) $ git stash apply stash@{1}
# 特定のstashを再適用して削除する(apply + drop) $ git stash pop stash@{1}
apply
とpop
は共にデフォルトで、stashを作業ディレクトリに再適用する- addしていた変更も、addされていない状態で戻る
- インデックスにも再適用したい場合は、後述の
--index
オプションを使う
pop
によってコンフリクトが発生した場合、そのstashは削除されない
# 特定のstashを作業ディレクトリとインデックスに再適用する $ git stash apply --index stash@{1} $ git stash pop --index stash@{1}
4. 退避した変更を削除する
# 特定のstashを削除する $ git stash drop stash@{1}
# 全てのstashを削除する
$ git stash clear
【参考】