Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert changes in the working directory only

Tags:

git

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?

like image 920
Stephen Rasku Avatar asked Oct 30 '12 20:10

Stephen Rasku


1 Answers

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.)

like image 117
Steve Avatar answered Sep 29 '22 08:09

Steve