Video: Revert a change in shared history
The video plays in YouTube’s player, in privacy-enhanced mode.
- 4 min video
- English narration · English and Arabic captions
- Watch on YouTube
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.
Video transcript
The narration of the video, cue by cue.
- Undo a change that other people already have.
- Reset moves the branch back. Revert adds a new commit instead.
- Others already have the old commit. Revert leaves their copy valid.
- Build the shared branch with a bad commit, and a local server that has it.
- The graph shows M, and the bad commit on top.
- The bad commit adds one line, and the text becomes pale.
- Write down its ID.
- Right-click it, and choose Revert Commit.
- It applies at once. There is no message editor.
- The notice says reverted.
- The new commit is named after the old one.
- Its parent is the bad commit. Nothing was removed.
- The file is back as it was. The pale rule is gone.
- And the graph shows both commits. The history only grew.
- Only this branch moved. Nothing is published yet.
- The branch is one commit ahead of the server.
- Click Push. This is a normal push.
- The notice names the branch and the server.
- No force was needed. The push only added a commit.
- In the terminal, git revert with no edit does the same.
- The bad commit is still an ancestor. The answer is zero.
- And the subject starts with Revert.
- Push, then compare the server's ID with HEAD. They are equal.
- Change the input: someone edited the same line later.
- The revert stops with a conflict. Resolve and continue, or abort.
- Reverting a merge asks for a parent. Usually it is the first.
- After reverting a merge, merging that branch again may do nothing.
- Practice: report the subject, parent, ancestor check and the server ID.
- Next, find a lost commit with the reflog.