Git checkout partial files after stashing in other branch

by user

Auto Draft

My Story

I was working topic branch and needed to experiment to implement hard algorithm. As I have some concern about working well, I shifted to other branch in order not to pollute current branch. Struggling some trial, I turned out that my experiment was obviously fail. Therefore I had to revert experiment branch to previous branch. But Only one file seemed to be effective in the previous branch. To return towards previous topic branch, I ought to stash scattered files into stash at first, otherwise get an error from git.

My procedures are:

1. Move from topic branch to experiment branch.
2. Exam trial code on the experiment branch.
3. Give up challenge.
4. Stash modified files so that I can shift to topic branch.
5. Push back to topic branch
6. Checkout partial files in stash into topic branch

sample

Apply files in stash

First of all, check stash list on topic branch

git stash show 
stash@{0}: WIP on master: 8cc3d02 Merge master into feature/scroll.
...skipping...
 README.md    | 69 +--------------------------------------------------------------------
 src/App.scss |  2 +-
 2 files changed, 2 insertions(+), 69 deletions(-)

Then apply files that I want to pick up

git checkout stash@{0} hoge.js hogehoge.js
Updated 1 path from bbd0b45

This is final file structure:

sample

If you are facing such a case, this post might be useful.

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Close Bitnami banner
Bitnami