git stash
git
書き方
git stash [push] [-u] [-m "<message>"]途中の変更を一時的にしまい、きれいな状態に戻します。既定では追跡外のファイルが残るので-uを付け、popは取り出して一覧から消し、applyは残します。
よく使うオプション
| オプション | 意味 |
|---|---|
| -u | include untracked files, which are otherwise left behind |
| -a | include ignored files too |
| -k | keep the staging area as it is |
| -p | stash selected hunks |
| pop | apply the newest entry and delete it |
| apply | apply it and keep the entry |
| list | show the entries |
| drop <stash> | delete one entry |
例
git stash -u -m "wip login"parks tracked and untracked changes under a name
git stash popbrings 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