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.
As noted in this answer, there is now a native git command which does this:
git restore --source=HEAD --worktree -- .
See the manpage.
I assume this should work (ordering matters).
You will first need to commit what is in the index (to make the HEAD look like this index and the working directory: B -- using your annotations):
git commit
So, the HEAD will be B (using your annotations).
Now, print the reflog as we will need the hash of B:
git reflog
Now, run a couple of reset
commands with different options:
git reset --hard HEAD~ # makes the working directory, the index, and the HEAD looks like this: A, A, A (respectively)
git reset --mixed <hashOfB> # makes the working directory, the index, and the HEAD looks like this: A, B, B (respectively)
git reset --soft HEAD~ # makes the working directory, the index, and the HEAD looks like this: A, B, A (respectively)
I hope this helps.
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