LoginSignup
12
10

More than 5 years have passed since last update.

git stash したファイルを選択的に適用・保存する方法

Last updated at Posted at 2015-10-09

文脈

git flow に則った並行開発をしていると feature ブランチで作業中に develop ブランチをマージすることがよくありますが、このとき git stash を使用している方は多いと思います。
マージ完了後にもとの作業に戻ろうとしたり、あるいは別ブランチで退避したファイルを適用したい場合に git stash pop あるいは git stash apply することになりますが、これらのコマンドは退避したファイル全てを適用しようとするので、都合が悪いことがあります。
そのようなときは下記のように git checkout を使えば良いことに気づいたのでメモしておきます。(stash を対象に git checkout できることに気づかなかった...)

適用

git checkout stash@{0} -- <filename>

保存

git show stash@{0}:<full/filename>  >  <newfile>

参考

How to apply files from stash selectively?

12
10
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
12
10