0
0

More than 3 years have passed since last update.

かゆいところに手が届くgit stash

Posted at

利用が想定される状況

 ・コミットする前に別の機能を実装する必要ができた
 ・今のコードの差分を別のコミットの後に回したい
 などが想定されます。
 
 そんな時に便利なのがgit stash 今ある差分を一時的に退避させることが可能です。

利用手順

 

$ git stash
Saved working directory and index state WIP on 02-setup: 8e4211a edit model

でコードを退避させ、別のコミットなどが終わった段階で、戻したいディレクトリに移動し、以下のコマンドでインデックスを確認します。

$ git stash list
stash@{0}: WIP on 02-setup: 8e4211a edit model

このstash@{0}が先ほど退避させたコードの番号で、複数あれば、stash@{1}などが確認できる。
今回は、直近で退避したstash@{0}を戻したいので以下のコマンドで戻せます。

$ git stash apply stash@{0}
On branch 02-setup
Your branch is ahead of 'origin/02-setup' by 1 commit.
  (use "git push" to publish your local commits)

以上が手順となります。コミットのし忘れなどの際に結構使う機会が多いように感じました。ジャンジャンgitを使いこなしてください:thumbsup_tone1:

0
0
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
0