Stash unstaged changes in git
I wanted to stash just the unstaged changes in my git repo. There’s a git stash --staged which will stash the staged files, but I didn’t see an equivalent to stash just the unstaged ones.
Obviously, this is a common problem so a minute or two of googling will find the Git stash uncached: how to put away all unstaged changes? Stack Overflow question.
Turns out that you have to remember the the staging area is also known as the index, so you need:
git stash --keep-index -u
If you’re wondering why the reverse operation didn’t use the index nomenclature, it’s because --staged was introduced in 2022 and nowadays the index is known as the the staging area, so staged is the obvious term to use. Why they didn’t create an --unstaged alias to --keep-index at the same time is anyone’s guess though.
The index is also called the cache, which is why git diff --cached does exactly the same thing as git diff --staged. In this case, they did create an alias to the modern term!
Naming things is hard.