You can use git revert --no-commit to undo changes from a particular change as we all know. This updates the working copy and the index, but does not commit the reversion. Is there any way to take this a step further and only update the working copy without updating the index? (i.e. the changes will be unstanged). I know you can use git checkout to get a working copy of a particular commit, but this also creates a detached head. I merely want to update the working copy with reverted changes.
You can use a temporary index to leave the original index undisturbed:
true_index=$(git rev-parse --git-dir)/index
export GIT_INDEX_FILE=.mytmpindex
cp "$true_index" .mytmpindex
git revert -n <some-commit-id>
rm .mytmpindex
unset GIT_INDEX_FILE
In the case where you have no staged changes that you wish to keep, you can simply do:
git revert -n <some-commit-id>
git reset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With