1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

git stash についてメモる。

1
Last updated at Posted at 2019-09-26

機能概要

stash を利用することで、コミットしていない変更を一時的に退避し、後ほど復活させることが可能。

利用シーン

  • とあるブランチで作業中だが、別ブランチで作業する必要が発生した。でもまだコミットしたくない。

  • 誤ったブランチで作業していて、コミット前の修正内容を意図するブランチに持っていきたい。

    といったところでしょうか。

コマンド一覧

(自分のために、)コマンドを整理しておく。

一時退避

$ git stash save "コメント"

※save以降は省略可能。

stashリストの表示

$ git stash list

※ハッシュ、コミットコメントはstashを行った時のHEADのもの。

stashリスト(内容込み)の表示

$ git stash list -p

stashリスト(詳細)の表示

$ git stash show <stash名>

stashの復活

$ git stash apply stash@{0}

※stashの指定を省略した場合、最新のstashが復旧される。

stashの復活&削除

$ git stash pop stash@{0}

stashの削除(stash指定)

$ git stash drop <消したいstash名>

※stash削除を行う際の注意:

stashの削除と共に、修正内容も削除されてしまうので気軽にやらないように。(私の場合、保存時のメッセージが気に入らなかったので削除→再stashを試みるも、そこにstashするもの[差分]が無いという地獄を。。)
と、言いたいところですが、、後述する「stashメッセージの修正」手順にて復旧可能なので参考までに。

stashの削除(全体)

$ git stash clear

stashメッセージの修正

// 一旦、stashを削除する。
$ git stash drop stash@{0}
Dropped stash@{0} (1234567890a1b2c3~~~~)

// 削除時に表示された情報(カッコ内の英数字)を利用して、storeを実行する。
$ git stash store -m "新たなメッセージ" 1234567890a1b2c3~~~~
1
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?