Tech Blog :: How to undo a file in a previous commit with Git


Sep 23 '10 3:22pm
Tags

How to undo a file in a previous commit with Git

Suppose you've made a bunch of commits in a Git repository, and need to undo the changes made to a specific file. git revert, git checkout, and git reset can all be used to undo/revert changes in different stages (see here), but this syntax seems to be best when individual files need to be rolled back:

git checkout REV -- path/to/file
where REV is the SHA of the last good commit

Post new comment

Don't bother putting in spam links. They'll be set to rel=nofollow and will be removed and reported as spam shortly after submitting.

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Are you human?