Stashing only un-staged changes in Git

git stash push has an option --keep-index that does exactly what you need.

So, run git stash push --keep-index.


This may be done in 3 steps: save staged changes, stash everything else, restore index with staged changes. Which is basically:

git commit -m 'Save index'
git stash push -u -m 'Unstaged changes and untracked files'
git reset --soft HEAD^

This will do exactly what you want.


git stash save --keep-index

Also, Re:

Why not commit your changes after staging them? – Shin

A: Because you should always checkin tested code :) That means, you need to run the tests with only the changes you are about to commit

All this apart from the fact that of course, as an experienced programmer, you have the innate urge to test and review just those changes -- only partly kidding

Tags:

Git

Git Stash