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

What if you want to stash the changes of only your work­ing direc­tory but not your index. One of the rea­sons you might want to do that is when you have an auto­mated pre-commit script that checks for jshint errors. Most scripts out there just exam­ine the work­ing direc­tory. An easy way out is to sim­ply stash your work­ing direc­tory, run the script on the staged files since they are now the same as the work­ing dir, com­mit and then pop the stash to get back the con­tents of your work­ing directory.

Here’s how you stash the work­ing direc­tory while keep­ing the staged files intact.

git stash save --keep-index

To get back your pre­vi­ous changes in the work­ing direc­tory, sim­ply run

git stash pop

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

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