I looked at a simple team doing the same thing, but it is not. Although you pointed out the correct way to do this in your question:
This will significantly apply the index-based reverse patch to the working directory.
So the answer is pretty simple:
git diff --no-color --staged | git apply --reverse
So you donβt have to do anything, just apply a backlink to your index.
Please note that if some changes in the working directory are not placed / in the index, they will not be undone in this way.
If you want to return everything to the working directory (even changes, not indexed and new files), except for the index itself, do the following:
git stash save --include-untracked --keep-index
You can remove it after that if you are not going to reuse it:
git stash drop
If you want to return everything except files without a trace (new files are not in the index)
Do it before:
git checkout .
To summarize, a few bash functions:
function git-unapply-index { git diff --no-color --staged | which git apply --reverse } function git-revert-workdir-keep-untracked { git checkout . git-unapply-index } function git-revert-workdir-all { git stash save --include-untracked --keep-index git stash drop git-unapply-index }
source share