David Froger David Froger - 3 months ago 8
Git Question

git "reset" workdir to HEAD without touching staging area

Using the same table representation as in

git-reset
manual page, I have these states in my
git
repository:

working index HEAD
------------------
B B A


What command will change the states to those?

working index HEAD
------------------
A B A


I other word, I want to "reset" the working directory state to the
HEAD
state, but without touching the staging area state.

Answer

A plumbing way of doing this is to manually backup and restore the index before and after doing git checkout:

cp .git/index .git/index.bak
git checkout HEAD -- .
mv .git/index.bak .git/index