Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (25 sloc) 692 Bytes
layout title date excerpt categories
Revert file after commit
2017-09-19 20:50:54 -4000
How to revert a file after it has been committed.
git commit reset

What if you accidentally committed file.txt, which you didn't intend to commit:

$ git commit -am "Commit all files"

How do you revert the file to its previous state before the commit?

The quick solution is to undo your last commit:

$ git reset HEAD~

However, you'll need to recommit everything all over again.

Alternatively, you could checkout the file at a state before it was committed:

$ git checkout HEAD~ -- file.txt

Then amend your commit:

$ git commit --amend
You can’t perform that action at this time.