git rebase -i HEAD~<number>
Interactively rebase the last <number> commits.
This command provides an interactive interface allowing you to modify the last <number>
commits.
This can include squashing multiple commits into one, rewording commit messages, or discarding commits entirely.
The -i
flag stands for interactive mode. HEAD~<number>
specifies the number of commits from the latest one (HEAD) to be included in the rebase. For instance, HEAD~3
refers to the last three commits. This command effectively enables you to rewrite commit history, but should be used with care as it can make collaboration difficult if not properly managed.
Specific examples:
git rebase -i HEAD~3