Background paper texture mobile
git

Revert Git Commit

revert git commit easy

Author avatar

Peter Shaan

June 22, 2026


6 Views

Open the terminal

git log --oneline

Example output:

m0n1o2p update README 
i7j8k9l fix: typo
e4f5g6h misc: add api endpoint. # 👈🏻 reverse this
a1b2c3d feat: login

Revert The Commit and Push

git reset --hard e4f5g6h
git push --force-with-lease

Safer Alternative: Revert

If other developers may already be using the commits, create a new commit that undoes the changes instead.

git revert --no-commit e4f5g6h..HEAD
git commit -m "revert commits after misc"
git push

Avoid Detached HEAD

Do not use Checkout (Detached) in VS Code to restore a branch.

It only lets you inspect an old commit temporarily and does not move the branch.

To move the current branch back to a specific commit, use:

git reset --hard <commit-hash>

Put in mind

git restore → mengembalikan file

git reset → memindahkan branch

git revert → membatalkan commit dengan commit baru


Back to Notes