Skip to content
GitTree

Video: Revert a change in shared history

The video plays in YouTube’s player, in privacy-enhanced mode.

Undo a bad change that others already have by adding a new commit that cancels it, instead of deleting history, and publish the fix with a normal push.

Read the full lesson

The article has every step and command from the video, the practice exercise and the questions.

Go to the lesson

Video transcript

The narration of the video, cue by cue.

  1. Undo a change that other people already have.
  2. Reset moves the branch back. Revert adds a new commit instead.
  3. Others already have the old commit. Revert leaves their copy valid.
  4. Build the shared branch with a bad commit, and a local server that has it.
  5. The graph shows M, and the bad commit on top.
  6. The bad commit adds one line, and the text becomes pale.
  7. Write down its ID.
  8. Right-click it, and choose Revert Commit.
  9. It applies at once. There is no message editor.
  10. The notice says reverted.
  11. The new commit is named after the old one.
  12. Its parent is the bad commit. Nothing was removed.
  13. The file is back as it was. The pale rule is gone.
  14. And the graph shows both commits. The history only grew.
  15. Only this branch moved. Nothing is published yet.
  16. The branch is one commit ahead of the server.
  17. Click Push. This is a normal push.
  18. The notice names the branch and the server.
  19. No force was needed. The push only added a commit.
  20. In the terminal, git revert with no edit does the same.
  21. The bad commit is still an ancestor. The answer is zero.
  22. And the subject starts with Revert.
  23. Push, then compare the server's ID with HEAD. They are equal.
  24. Change the input: someone edited the same line later.
  25. The revert stops with a conflict. Resolve and continue, or abort.
  26. Reverting a merge asks for a parent. Usually it is the first.
  27. After reverting a merge, merging that branch again may do nothing.
  28. Practice: report the subject, parent, ancestor check and the server ID.
  29. Next, find a lost commit with the reflog.

All tutorials