>_ IzzyLab

Hands-on task

This task is step 10 of the course “Git: rewriting and rescuing history”

Squash a fixup commit via autosquash

hard~15 min

In /root/repo (branch main) there are three commits: base, add config (creates config.txt with the line value=1) and add readme. There's a mistake in the config — it should be value=2.

Fix it the right way: make a separate fix commit marked as fixup! for the add config commit (with config.txt = value=2), and then non-interactively squash it into the target commit via an autosquash rebase. In the end the history should again consist of three commits (base, add config, add readme), without a separate fixup! commit, and the value=2 change should end up inside the add config commit.

Run the rebase without a manual editor: set GIT_SEQUENCE_EDITOR=true to automatically accept the generated action list.

What you'll practise:
  • git commit --fixup
  • autosquash
  • git rebase -i
  • GIT_SEQUENCE_EDITOR
  • rewriting history

Topic breakdown

Autosquash is a two-step pipeline: first the fix is formed as a special commit whose message starts with fixup! <target title>, and then an interactive rebase with the --autosquash flag automatically places it next to the target commit and merges it in, leaving no trace. A fixup commit is conveniently made via git commit --fixup <target>. For the rebase to run non-interactively, the action-list editor is substituted by setting GIT_SEQUENCE_EDITOR=true — git will accept the generated plan as is.

What's checked

  1. exactly three commits in history
  2. no separate fixup commit
  3. the fix is inside the add config commit

What it looks like