Git: Revert Change

By Xah Lee. Date: . Last updated: .

How to revert a file?

git checkout -- file_name

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

How to revert a directory?

git checkout HEAD -- dir_full_path

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

How to Revert a File to Last Commit?

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

If you have a question, put $5 at patreon and message me.

git

  1. Install git
  2. Git Basics
  3. Git Ignore File
  4. Commit Files
  5. Push to Server
  6. Pull from Server
  7. Find Difference
  8. View Log
  9. Revert Change
  10. Branching
  11. Temp Save: git stash
  12. What's HEAD
  13. FAQ