Menu
Coddy logo textTech

Revert A Commit

Part of the Version Control section of Coddy's Terminal journey — lesson 43 of 58.

If a commit has already been shared with others, amending it is risky because the original ID is gone. The safer option is git revert.

git revert HEAD

git revert creates a brand-new commit that undoes the changes from the target commit, leaving the original in place. Your history reads as: "we did X, then we undid X".

You can revert any commit by ID, not just the latest one:

git revert a1b2c3d

Use --no-edit to skip the editor and accept the default revert message:

git revert --no-edit HEAD

The default message looks like Revert "Original subject", with the original message echoed in the body.

challenge icon

Challenge

Easy

The folder contains app.txt. Initialize the repo and create two commits:

  1. Add app.txt with message Add app.
  2. Append broken to app.txt and commit with message Add broken line.

Revert the latest commit (no editor) to undo the broken line. Print the contents of app.txt.

Cheat sheet

git revert creates a new commit that undoes changes from a target commit, preserving history:

git revert HEAD          # revert latest commit
git revert a1b2c3d       # revert any commit by ID
git revert --no-edit HEAD  # skip editor, use default message

The default revert message follows the format: Revert "Original subject".

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control