Skip to content
GitTree

Video: Reorder, squash, reword and drop local commits

The video plays in YouTube’s player, in privacy-enhanced mode.

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.

Go to the lesson

Video transcript

The narration of the video, cue by cue.

  1. Five rough commits become two clean ones, safely.
  2. Interactive rebase is a plan: a list of steps, oldest first.
  3. Git replays the list from top to bottom on a base.
  4. Each step gets an action: pick, reword, squash, fixup or drop.
  5. First, build five private commits and a rescue branch.
  6. Three are real work. One is a fix, and one is temporary noise.
  7. Right-click the commit below them, and open Edit History.
  8. Choose Interactive Rebase of the Commits Above.
  9. The editor lists the five steps, oldest first.
  10. Leave all three options off. We will move the fixup ourselves.
  11. The fixup belongs right after the commit it fixes. Move it up twice.
  12. Now move the validation note above the review note.
  13. The order is now one, four, three, two, five.
  14. Set the first step to Reword, and write the new message.
  15. Set the fixup step to Fixup. Its message is thrown away.
  16. Keep the validation note, and squash the review note into it.
  17. Squash shows both messages. Write one message for the pair.
  18. Drop the temporary note. Its change will not survive.
  19. Read every row once more. Nothing is on a remote.
  20. Choose Start Rebase once, and wait for it to finish.
  21. The graph now has two commits above the base.
  22. Both have new IDs. The old five are on the rescue branch.
  23. Open the page: the label fix is there. The noise is gone.
  24. Now the same plan in the terminal, with git rebase -i.
  25. Git opens the todo list. Oldest first, all set to pick.
  26. Rewrite the lines into our plan: reword, fixup, pick, squash, drop.
  27. Git asks for the two messages. Write one line for each.
  28. Count the commits above the base: two.
  29. List the subjects. These are the two we wrote.
  30. Status is empty, and the temporary note is gone.
  31. Change the input: put the squash on the first step.
  32. There is nothing above it to fold into, so Git refuses.
  33. Or move the fixup above its commit: the replay stops with a conflict.
  34. If it stops, fix it and continue. Or abort, and nothing changes.
  35. The rescue branch still holds your original five commits.
  36. Never rewrite commits that someone else already has.
  37. Practice: explain the plan, and why step one cannot be a squash.
  38. Next, resolve conflicts when a merge or a rebase stops.

All tutorials