Skip to content
BENIBIX Learn

Git Revert

Development🔀 Version ControlUndo Commands

Also known as git revert, Revert a Commit, Revert Commit

A new commit that undoes an old one. The old one stays in the history.

Think of it like

Think of it like a new diary line that says to forget what you wrote yesterday. The old page stays.

Example

A bad change broke the order page on main. Jack reverts that commit, pushes, and the site works again.

Why it matters

It is the safe way to undo on a shared branch. Nobody's copy of the history breaks.

Definition

Git revert undoes a commit by making a new commit that does the opposite. If the old commit added a line, the new one takes it out. The old commit stays in the history. Nothing is deleted or rewritten. That makes it safe on a branch other people already have.

Example code

console
$ git revert 7b8c9d0
[main 5e6f7a8] Revert "Fix the price on the order page"
 1 file changed, 1 insertion(+), 2 deletions(-)
A new commit undoes the old one, and both stay in the history.
Revert adds commit D, which undoes C. Nothing is removed.

Common mistake

Using git reset on a branch others have pulled. Revert is the undo that does not rewrite history.

Key takeaways

  1. 1
    Adds, never deletes. The undo is a new commit.
  2. 2
    Safe to share. History is not rewritten.
  3. 3
    One commit at a time. Name the commit to undo.

Compare

Learn it properly