git stash

git

書き方

git stash [push] [-u] [-m "<message>"]

途中の変更を一時的にしまい、きれいな状態に戻します。既定では追跡外のファイルが残るので-uを付け、popは取り出して一覧から消し、applyは残します。

よく使うオプション

オプション意味
-uinclude untracked files, which are otherwise left behind
-ainclude ignored files too
-kkeep the staging area as it is
-pstash selected hunks
popapply the newest entry and delete it
applyapply it and keep the entry
listshow the entries
drop <stash>delete one entry

git stash -u -m "wip login"

parks tracked and untracked changes under a name

git stash pop

brings the newest stash back and removes it from the list

git stash apply stash@{2}

applies an older entry and leaves it in the list

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git stash は何をしますか。

途中の変更を一時的にしまい、きれいな状態に戻します。既定では追跡外のファイルが残るので-uを付け、popは取り出して一覧から消し、applyは残します。

Q. どう打ちますか。

git stash [push] [-u] [-m "<message>"] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは8個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-stash