0
2

More than 1 year has passed since last update.

【Git】git stashを使ってファイルを一時退避させる

Posted at

はじめに

現在作業途中だけど、他のブランチで別の作業を行わなければならないから、現在の作業はコミットせずにファイルを一時退避させたいというときに、git stashを使います。
git commitしていないファイルが対象なので、git addはしていてもしていなくても退避させることができます。

コマンド

git stash

・ワークツリー及びステージにあるファイルを一時退避させます。
・前回のコミット後に新規作成されたファイルは退避に含まれません。
・saveはあってもなくても良いです。
・複数回git stashを行うと、stash{0} stash{1} stash{2}といった感じで何回目のstashかが分かるようになります。

ターミナル
git stash
git stash save

git stash -u

git stashと異なり、前回のコミット後に新規作成されたファイルも退避に含まれます。

ターミナル
git stash -u

git stash list

・一時退避させた作業の一覧を確認することができます。

ターミナル
git stash list

git stash apply

・一時退避させた作業の復元を行います。

ターミナル
git stash apply              //最新の作業(1番直近で退避した作業)を復元
git stash apply stash{1}     //stash{1}という特定の作業を復元
git stash apply --index      //addされたものはaddされたままの状態で復元

git stash drop

・一時退避した作業を削除します。

ターミナル
git stash drop               //最新の作業(1番直近で退避した作業)を削除
git stash drop stash{1}      //stash{1}という特定の作業を削除
git stash clear              //すべての作業を削除
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2