Gitの小ネタおれおれAdvent Calendar 2022 – 06 日目
作業状態をいったん保留できる stash は便利コマンドですが、新規作成してまだ Git に登録していないファイル (untracked files) は残っちゃいます。
これらのファイルも一緒に棚上げするには -u オプションを与えます。
$ git stash -u
-u, --include-untracked
git stash push で使えるオプション。
その名の通り untracked なファイルも対象にしてくれます。
以下 git stash --help より。
If the
--include-untrackedoption is used, all untracked files are also stashed and then cleaned up withgit clean, leaving the working directory in a very clean state. If the--alloption is used instead then the ignored files are stashed and cleaned in addition to the untracked files.
追加済みの新規ファイルには不要
これまでのコミットにはない新しいファイルでも、一度 git add して staged 状態にしてやると -u オプションなしでも対象にしてくれます。
まあ add したことで Git に登録されたということですかね。
-a は使うな
-a ないし --all は未登録のファイルだけでなく無視リストに入ってるファイル、例えば node_modules なんかも stash の保管庫へ移してしまいます。嬉しくないですね。