Skip to content
Justice Tech School

Revert a Commit

git revert makes a new commit that undoes an old one without rewriting history.

Example
echo one > a.txt && git add a.txt && git commit -qm 'first'
echo two >> a.txt && git commit -qam 'add two'
git revert --no-edit HEAD >/dev/null
git log --format=%s | head -n 1 | cut -c1-6
cat a.txt

Result

Revert
one

Exercise

Undo safely.

git  HEAD

Quiz Test

Why use revert on shared branches?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.