Ask Steves · Daily notes · VPS, 20% off · AI Profit Lab · SEO · Money Hub

13 November 2026 · One command a day

How do I undo the last git commit without rewriting history?

git revert HEAD undoes the last commit by adding a new commit that does the exact opposite. The bad change goes from your files but the history stays as it was. Nothing is lost, and anyone who has already pulled is not left with a broken copy. Use it when a commit you just made, or just deployed, turns out to be wrong.

I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.

The command

cd /var/www/appname
git revert HEAD

git revert works out the reverse of a commit and saves it as a new commit. HEAD means the commit you are on now, which is usually the last one you made. Git opens your text editor with a ready-made message such as Revert "Update upload limit". Save and close it to finish. Add --no-edit to accept that message without the editor, which helps in scripts. To undo an older commit, put its short hash in place of HEAD.

What you will see

[main 7c1e4b2] Revert "Change upload limit for example.com"
 1 file changed, 1 insertion(+), 1 deletion(-)

The first line shows the branch, the hash of the new commit and its message. The second line counts what changed. The line the original commit added is removed, and the line it removed comes back. If you then list recent commits one line each, you will see the original commit with the revert directly above it.

When to use it

Watch out for

A revert only changes the files in the repository. It does not change what is already running. If your app loads its code when it starts, or your site needs a build step, the live site stays the same until you rebuild or restart it, for example with pm2 restart appname. If you reverted an nginx file, run sudo nginx -t and then sudo systemctl reload nginx. Many people revert, see the same error, and think the revert failed, when the old process is just still running.

Questions people ask

Does git revert delete the original commit?

No. The original commit stays in the history and a new commit cancels it out. That is why it is safe on a branch you have already pushed.

How do I undo a revert?

Revert the revert. Run git revert HEAD again straight after it, and the original change comes back as another new commit.

Rolling back a live config in seconds is the kind of thing you can only do on a server you control. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.

Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.

Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.

GET A VPS, 20% OFF →

Affiliate link.

Related server notes: How do I see recent git commits in one line each on Linux? · How do I copy a git repository onto my Linux server? · How do I follow a Docker container's logs on Linux? · All daily notes