Practical Git guide

Undo a pushed Git commit with revert

Reverse a shared change with git revert while preserving the original commit and remote history.

Before you start

A bad sentence has already reached a shared branch. Create a new reversing commit instead of deleting the published one. A local bare remote makes this example reproducible without a hosting account.

Use Git 2.28 or newer in a POSIX shell on macOS/Linux, or Git Bash on Windows. Check git --version; Git's installation page covers setup. Each example starts in a new temporary folder. Keep that folder if you want to revisit your work; none of these commands removes your existing projects. The identity and signing settings below apply only to the practice repository.

Work through the example

practice=$(mktemp -d "${TMPDIR:-/tmp}/gitglow-learn.XXXXXX")
sandbox="$practice/project"
mkdir "$sandbox"
cd "$sandbox"
git init -b main
git config --local user.name "Git Learner"
git config --local user.email "learner@example.invalid"
git config --local commit.gpgsign false
git init --bare -b main origin.git
git clone origin.git alice
cd alice
git config --local user.name "Git Learner"
git config --local user.email "learner@example.invalid"
git config --local commit.gpgsign false
printf 'A small project\n' > notes.txt
git add notes.txt
git commit -m "Start notes"
git push -u origin main
cd ..
git clone origin.git bob
cd bob
git config --local user.name "Second Learner"
git config --local user.email "second@example.invalid"
git config --local commit.gpgsign false
cd ../alice
printf 'Wrong published advice\n' >> notes.txt
git add notes.txt
git commit -m "Publish incorrect advice"
git push
bad_commit=$(git rev-parse HEAD)
git revert --no-edit "$bad_commit"
git log -3 --oneline
cat notes.txt
git push
cd ../bob
git pull --ff-only
git log -3 --oneline

Check the result

Both clones contain three commits: the starting commit, the incorrect change, and its revert. The unwanted line is absent from notes.txt, but the original bad commit remains in history. No force-push is needed. Revert applies the inverse patch and may conflict when later changes overlap.

Try it yourself

Compare git show HEAD with git show HEAD~1. Explain how the two patches oppose each other while both commits remain reachable.

If something goes wrong

If revert conflicts, inspect git status, resolve and stage the affected files, then use git revert --continue; git revert --abort cancels that active revert. Reverting a merge requires choosing a mainline parent and is outside this single-parent example.

Use this workflow in GitGlow

Inspect the published commit in History. GitGlow Pro offers a guarded Revert preview and operation recovery. The Free terminal can run ordinary Git revert commands; supported conflict resolution and Continue/Abort remain available on Free. Inspect and test the result before publishing.

Download GitGlow Free

Go deeper with the official Git docs

These references cover command options and behavior beyond this example.