メモ。
Git管理下のプロジェクトで、下記の hoge/fuga/file1.txt hoge/fuga/file2.txt のような差分ファイルがあり、別の作業をしたくなってこれらを一旦 git stash で一時退避したとする。
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: hoge/fuga/file1.txt
modified: hoge/fuga/file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash
Saved working directory and index state WIP on master: d1daeee second commit.
$ git stash list
stash@{0}: WIP on master: d1daeee second commit.
このあと、やっぱり hoge/fuga/file1.txt の差分だけ欲しくなった。
このようなとき、以下のようにしてstash中の一部のファイルを取り出すことができる。
$ git checkout @stash@{1} hoge/fuga/file1.txt
stashのインデックスと、その中での差分ファイルのうち一つを指定する。
ちなみに、n番目のstash中ファイル一覧は以下で見れる。
$ git stash show stash@{n}