CodeBlanks Logo Icon CodeBlanks

Summary - Interactive rebase

Combine interactive rebase commands to rewrite history.

Summary: Interactive rebase

Interactive rebase is a powerful tool for reorganizing commit history. pick keeps a commit, reword changes its message, squash combines it with the previous commit, edit pauses for modifications, and drop removes a commit.

git rebase -i HEAD~5

After editing the todo list, complete the steps requested by Git. When the operation pauses, you can modify changes; when ready, use git rebase --continue.

Practice Turn multiple commits into one entry

Start an interactive rebase for the last four commits. In the todo list, keep the first commit and combine the next three commits with the previous entry. Use the commit IDs and descriptions below.

Starter code

terminal
# İnteraktif rebase başlat

# Todo listesinde dört commit'i düzenle

Sample solution

terminal
git rebase -i HEAD~4
pick a10bc20 Add invoice model
squash b20cd30 Add invoice validation
squash c30de40 Add invoice tests
squash d40ef50 Fix invoice labels

Expected output

Interactive rebase started.
pick a10bc20 Add invoice model
squash b20cd30 Add invoice validation
squash c30de40 Add invoice tests
squash d40ef50 Fix invoice labels

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 You want to remove an unnecessary temporary commit from a feature branch while keeping the other commits. Which todo operation should you use?

  • edit
  • squash
  • reword
  • drop Correct answer

Explanation: drop removes the selected commit from the rewritten history while the other commits are handled according to the todo list.

2 Start an interactive rebase session

Question
git ____
Answer
git rebase -i HEAD~6

Explanation: Use git rebase -i to edit commit history interactively.

3 Combine interactive rebase commands

Term Meaning
pick Replay the commit
reword Rewrite the message
squash Combine with the previous entry
drop Remove the entry from history

All lessons in Advanced