Git: Revert to Old Version

By Xah Lee. Date: . Last updated: .

Revert a File

git checkout -- filename

This will update the file filename in working directory. It'll be from your local repository. Effectively, revert whatever you've done to the file.

Revert a Directory

git checkout HEAD -- dirFullPath

This will update the dir dirFullPath to the commit version in HEAD. (typically the last commit.) Replace HEAD by a commit hash to revert to other version.

Revert a File to Last Commit

# revert file to last commit
git checkout HEAD -- filename
# revert file to the commit before last commit
git checkout HEAD^ -- filename

Revert a File to Specific Commit

# revert a file of specific commit
git checkout b9d6f -- filename

use git log to find the commit id. [see Git: View History/Log]

git FAQ

git

git FAQ