Stash just a single file

EoghanM picture EoghanM · Sep 14, 2012 · Viewed 180.3k times · Source

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?

Answer

Wes Hardaker picture Wes Hardaker · Sep 14, 2012

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 master

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.