Reputation: 9464
EDIT I am looking for a single command
Please note I am looking for file specific operation and not commit level operations. At commit level I know it can be done using different flags. So here is my scenario:
I have a single file: test.txt
My repo file contains a text:
first change
My staging file AND my working dir file contains a text:
first change second change
Now if I do
git rest HEAD test.txt
the state of affairs is following
first change
[nothing changed here]first change
[changed to match repo file]first change second change
[nothing changed here]What is the command to get into following state:
first change
[nothing changed here]first change
[changed to match repo file]first change
[changed to match repo file]Upvotes: 1
Views: 524
Reputation: 213261
I always do this with git reset HEAD file
followed by git checkout -- file
.
You can also do this with a single command (this I came to know of recently):
git reset --hard HEAD file # oops!! doesn't work on paths...
Seems like the previous command doesn't work on paths. In that case, you can use this one:
git checkout HEAD -- file
Note the usage of --
. That will replace both staged and working copy of that file.
Upvotes: 4