rebase -i
- Git course
- Advanced
- Lesson 1/56
- 4 min
Learn interactive rebase with git rebase -i.
Introduction to interactive rebase
Interactive rebase lets you reorganize entries in commit history. The git rebase -i command opens a todo list in an editor, where you choose how each commit should be handled. For example, use HEAD~4 to inspect the last four commits.
git rebase -i HEAD~4The order of the lines in the editor determines the order in which commits are replayed. Save the list and exit the editor to continue the operation.
Reading the todo list
Each line in the interactive rebase editor contains an operation and commit information. The command at the beginning of the line specifies what should happen to that commit. For example, pick replays the commit as it is; other commands can change its message or structure.
pick a12bc34 Add search form
pick b23cd45 Fix search validation
pick c34de56 Update search stylesYou can change the commit order and selected operations by editing the lines.
Practice Prepare the interactive rebase command
Write the Git command to inspect the last five commits in the editor. Enable interactive mode and select the correct commit range.
Starter code
# Son beş commit için interaktif rebase başlatExpected output
Interactive rebase started for the selected commit range.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the main purpose of the todo list opened by an interactive rebase?
- Create a new remote repository
- Download files from the remote repository
- Define how commits should be handled Correct answer
- Delete all files in the working directory
Explanation: The todo list defines the operations to perform on the selected commits and their order.
2 Start an interactive rebase for the last three commits
git rebase ____
git rebase -i HEAD~3
Explanation: The -i option enables interactive mode. HEAD~3 specifies the range containing the last three commits.
3 Interactive rebase interface
| Term | Meaning |
|---|---|
Todo listesi |
Contains operation lines |
Düzenleyici |
Allows editing the list |
Commit kimliği |
Identifies the relevant commit |
Satır sırası |
Determines replay order |