Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git basics
  6. Undoing changes
  7. Undoing commits
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Undoing commits

Use the git revert command to undo previous commits. This is the most common method of undoing changes.

The revert command creates a new commit that reverts the changes made by a previous commit. It allows you to undo unwanted changes without removing the commit entirely or modifying the repository's history. It’s a useful tool for managing changes to a Git repository while preserving its history.

While you can delete a prior commit from the history using the commands git reset or git rebase -i, it is generally not recommended because it causes the remote repository to diverge from the local repositories of other members.

Diagram of reverting commits.
Git revert is the safest method of undoing changes.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life