Stash just a single file

Total
0
Shares

I’d like to be able to stash just the changes from a single file:

git stash save -- just_my_file.txt

The above doesn’t work though. Any alternatives?


Solution

I think stash -p is probably the choice you want, but just in case you run into other even more tricky things in the future, remember that:

Stash is really just a very simple alternative to the only slightly more complex branch sets. Stash is very useful for moving things around quickly, but you can accomplish more complex things with branches without that much more headache and work.

# git checkout -b tmpbranch
# git add the_file
# git commit -m "stashing the_file"
# git checkout main

go about and do what you want, and then later simply rebase and/or merge the tmpbranch. It really isn’t that much extra work when you need to do more careful tracking than stash will allow.

Source: StackOverflow.com

Leave a Reply

Your email address will not be published. Required fields are marked *