Skip to content

Git rebase interactive

Git rebase interactive is a variation of the standard rebase operation used to modify, reorder, or squash multiple commits within a branch history.^[600-developer-tools-git-git-command.md]

Usage

To begin an interactive rebase, the command is executed against a specific commit hash (the parent of the commits you wish to edit):^[600-developer-tools-git-git-command.md]

[Git rebase](<./git-rebase.md>) -i 1c76461a21a8

Squashing Commits

A common use case for interactive rebase is combining multiple commits into one.^[600-developer-tools-git-git-command.md] This is often referred to as "commit compression" or a "衍合操作" (rebase operation).^[600-developer-tools-git-git-command.md]

To squash commits: 1. Run the git rebase -i <commit-id> command. 2. In the editor that appears, mark the first commit as pick. 3. Change the status of all subsequent commits you wish to merge into the first one to squash.1 4. Save and close the file to proceed.

Sources

  • 600-developer-tools-git-git-command.md

  1. The source instruction specifies: "第一條pick其他全部改为squash" (The first line is pick, change all others to squash).^[600-developer-tools-git-git-command.md]