Changing history
Undoing changes with restore, reset, revert and the reflog; rebasing; and stashes, tags and semantic versions.
About 4 hours of study
Learning objectives
- Choose the right undo command
- Rebase and tidy commits safely
- Stash work and tag releases
Lessons
- 1
Undoing changes: restore, reset, revert and the reflog Intermediate
Fix mistakes at every stage: discard edits with git restore, unstage files, move a branch back with git reset in its three modes, undo a shared commit safely with git revert, amend the last commit, and recover "lost" commits from the reflog.
- 2
Rebasing Advanced
Move a branch's commits onto a new base to keep history linear. See which commits a rebase replays, rewrite commits with an interactive rebase (reword, squash, fixup, drop), handle conflicts commit by commit, and follow the golden rule of rebasing.
- 3
Stashing work and tagging releases Intermediate
Put unfinished work aside with git stash while you fix something urgent, and mark releases with tags. Use semantic versioning to name versions, compare them correctly, and describe any commit relative to the latest tag.
Module practice
- Git: The three reset modesEasy
- Git: Revert a commitMedium
- Git: Recover commits with the reflogHard
- Git: Which commits will be replayed?Easy
- Git: Apply an interactive rebase to-do listMedium
- Git: Replay commits and stop at a conflictHard
- Git: Sort version tagsEasy
- Git: The stash stackMedium
- Git: Describe a commit by its nearest tagHard