I have a broken merge and I want to revert changes in the working directory to find out where it's broken. I want to preserve the index so I can add the fixes to it and eventually check them in. Essentially, I want the working directory to be the same as the HEAD but without modifying the index. This essentially would apply a reverse patch based on the index to the working directory. It seems like this would be the opposite of a git reset
.
How do you do this in git?
You could commit the index, reset the working directory, and then reset the commit.
$ git commit -m "blah"
$ git reset --hard
$ git reset --soft HEAD^
Edit: It seems I misunderstood the original question.
To reset the working tree to HEAD without disturbing the index, do the following:
$ git checkout -- .
$ git diff --cached | git apply --reverse
(And it looks like @Brice already gave this answer.)
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