>_ IzzyLab

Hands-on task

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

Add a line to an old commit with rebase edit

hard~15 min

In /root/repo there are three commits. The middle one (add config) created the file config.ini, but the line timeout=30 was forgotten in it. Add this line to that very commit — as if it was never forgotten: config.ini in that commit must contain timeout=30, the number of commits must stay the same (three), and the third commit (add readme) must come after the fixed one, as before.

What you'll practise:
  • git rebase -i
  • editing a commit
  • git commit --amend
  • rebase --continue
  • rewriting history

Topic breakdown

An interactive rebase can not only drop commits but also stop at a chosen one for editing: in the script, the action pick is changed to edit on the right line, and git rewinds the history to that commit, handing over control. Then the change is folded into the current commit via amend (which appends to the existing commit rather than creating a new one), after which the rebase replays the rest. This way the change ends up "inside" the old commit, while the number of commits and their order don't change.

What's checked

  1. timeout=30 in the middle commit
  2. still three commits
  3. order preserved

What it looks like