• 0

How to stash the contents of only the working directory but not index

What if you want to stash the changes of only your working directory but not your index. One of the reasons you might want to do that is when you have an automated pre-commit script that checks for jshint errors. Most scripts out there just examine the working directory. An easy way out is to simply stash your working directory, run the script on the staged files since they are now the same as the working dir, commit and then pop the stash to get back the contents of your working directory.

Here's how you stash the working directory while keeping the staged files intact.

git stash save --keep-index

To get back your previous changes in the working directory, simply run

git stash pop