Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I revert one file to its original state in git?

Tags:

git

I have a few files I made changes to.

Then I committed it and realized I made a change to a file I didn't want to change. How can I get the file back to its original state? I am on a branch.

git checkout --file

didn't do anything at all.

like image 421
u_ser722345 Avatar asked Jun 05 '13 23:06

u_ser722345


3 Answers

git checkout filename

will work in most cases, unless you have a branch with the same name as a file. In either case,

git checkout -- filename

will be sufficient.

like image 54
amalloy Avatar answered Nov 03 '22 01:11

amalloy


You need a space between -- and your filename:

git checkout -- filename
like image 34
Johnsyweb Avatar answered Nov 03 '22 01:11

Johnsyweb


Try

git checkout HEAD~ filename

instead.

like image 4
dyng Avatar answered Nov 03 '22 00:11

dyng