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?
If you do not want to specify a message with your stashed changes, pass the filename after a double-dash.
$ git stash -- filename.ext
If it's an untracked/new file, you will have to stage it first.
However, if you do want to specify a message, use push
.
git stash push -m "describe changes to filename.ext" filename.ext
Both methods work in git versions 2.13+
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With