user993563
user993563

Reputation: 19371

Reverting changes in only one file via GIT

I have a templates directory with around 10 *.html files. I made changes to most of them. Now i want to revert changes only in the index.html file. How can i do that:

if i have committed my latest changes? if i have not committed my latest changes? (i dont want to git reset --HARD which will undo all the changes)

Upvotes: 1

Views: 120

Answers (2)

ThatOtherPerson
ThatOtherPerson

Reputation: 834

If you haven't committed:

git checkout index.html

If you have committed, use git log to find the commit id you wish to revert, such as 3a765c6cd6316a665cca789d11a7186234c203a8 and type:

git checkout 3a765c6cd6316a665cca789d11a7186234c203a8 -- index.html

Upvotes: 1

Patrick B.
Patrick B.

Reputation: 12333

Try

git checkout -- index.html

for when you haven't committed yet.

If you have committed you need to git reset [--mixed] the last commit, do the git checkout and git commit again.

Upvotes: 4

Related Questions