MicrolearnENPTES

revert: undo a published commit

Lesson 23 of 24 · Git.Micro

Once a commit is on the server, don't rewrite history. git revert creates a new commit that does the exact opposite of the old one.

git revert <hash> undoes any commit, even an old one, and keeps the history intact.

Because it only adds a commit, your teammates can pull it normally.

Rule of thumb: reset and amend for local commits, revert for commits that are already shared.

Check yourself

Why is git revert safe for commits that are already pushed?

It adds a new commit instead of changing the existing ones

The commit Remove search box was a mistake, and it's already on the server. Undo it without rewriting history, then push.

Do it in the browser: a real Git tool, a short mission and instant feedback. No install.

Start this lesson — free
← reset: move a branch backRebase and cherry-pick →

All lessons · Git.Micro