Video: Reorder, squash, reword and drop local commits
The video plays in YouTube’s player, in privacy-enhanced mode.
- 7 min video
- English narration · English and Arabic captions
- Watch on YouTube
Turn five rough private commits into two clean ones: move a dependent fix, reword a message, fold and squash steps, drop only the noise, and check that the result has exactly the files you meant.
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.
- Five rough commits become two clean ones, safely.
- Interactive rebase is a plan: a list of steps, oldest first.
- Git replays the list from top to bottom on a base.
- Each step gets an action: pick, reword, squash, fixup or drop.
- First, build five private commits and a rescue branch.
- Three are real work. One is a fix, and one is temporary noise.
- Right-click the commit below them, and open Edit History.
- Choose Interactive Rebase of the Commits Above.
- The editor lists the five steps, oldest first.
- Leave all three options off. We will move the fixup ourselves.
- The fixup belongs right after the commit it fixes. Move it up twice.
- Now move the validation note above the review note.
- The order is now one, four, three, two, five.
- Set the first step to Reword, and write the new message.
- Set the fixup step to Fixup. Its message is thrown away.
- Keep the validation note, and squash the review note into it.
- Squash shows both messages. Write one message for the pair.
- Drop the temporary note. Its change will not survive.
- Read every row once more. Nothing is on a remote.
- Choose Start Rebase once, and wait for it to finish.
- The graph now has two commits above the base.
- Both have new IDs. The old five are on the rescue branch.
- Open the page: the label fix is there. The noise is gone.
- Now the same plan in the terminal, with git rebase -i.
- Git opens the todo list. Oldest first, all set to pick.
- Rewrite the lines into our plan: reword, fixup, pick, squash, drop.
- Git asks for the two messages. Write one line for each.
- Count the commits above the base: two.
- List the subjects. These are the two we wrote.
- Status is empty, and the temporary note is gone.
- Change the input: put the squash on the first step.
- There is nothing above it to fold into, so Git refuses.
- Or move the fixup above its commit: the replay stops with a conflict.
- If it stops, fix it and continue. Or abort, and nothing changes.
- The rescue branch still holds your original five commits.
- Never rewrite commits that someone else already has.
- Practice: explain the plan, and why step one cannot be a squash.
- Next, resolve conflicts when a merge or a rebase stops.