shellstreak

Undo a commit you already pushed

Safe: nothing is lost

Short answer

Run git revert --no-edit <commit> and push. Git adds a new commit that undoes it, so nobody's history breaks.

The commands, one by one

  1. 1git revert --no-edit HEAD

    Makes a new commit that does the exact opposite of the latest one (HEAD). --no-edit accepts git's message, Revert "…".

  2. 2git push

    Shares the undo. Everyone gets it with their next pull.

For your own repository: For an older commit, give its hash from git log --oneline instead of HEAD.

Try it safely

You pushed Turn on debug mode to main and it broke the shop.

learner@shellstreak: ~
Starting your practice shell…

Type your own commands too. Reset puts the repository back to just after the mistake.

Practise this in 5 minutes

Lesson 32, Undo the agent's mistakes, walks you through this undo and the ones around it in a safe terminal, step by step, and checks your answers.

Keep the terminal cheat sheet handy: free to print

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.