Skip to main content
Junior

Reversing Changes in Git

Junior

Task

Undo the latest changes in two branches, taking into account whether the history has been published or not.

Steps

  1. In the local branch, remove the last local commit by rewriting history.
  2. Switch to the pushed branch.
  3. Undo its last published commit with a new reverting commit, without moving the branch backward.

Expected result

local must return to C1. The pushed branch must get a new revert commit on top of C2, and HEAD must stay on pushed.

What you will learn

After completing the task, you will be able to:

  • choose between reset and revert;
  • safely undo published changes;
  • understand the difference between rewriting history and adding a new reverting commit.
Goal
localC0C1main localC2C2'HEAD pushedC3
Git trainer0 commands
terminal
localC0C1mainC2pushedC3HEAD local