Git rebase for commit squashing¶
Git rebase for commit squashing is a technique used to combine multiple commits into a single one, often referred to as "compressing" commits.^[600-developer__tools__git__git-command.md] This process helps in cleaning up commit history before pushing changes or merging branches.
Execution¶
To perform a squash, the interactive rebase command is used^[600-developer__tools__git__git-command.md]:
[Git rebase](<./git-rebase.md>) -i <commit-hash>
For example, using git rebase -i 1c76461a21a8 initiates an interactive session targeting the commits made after the specified hash^[600-developer__tools__git__git-command.md].
Process¶
Once the command is run, a text editor will appear listing the commits^[600-developer__tools__git__git-command.md]. To squash multiple commits into one:
- Keep the first (oldest) commit in the list marked as
pick. - Change the status of all subsequent commits you wish to merge from
picktosquash. - Save and close the file to proceed^[600-developer__tools__git__git-command.md].
Git will then combine the changes and prompt you to create a new commit message for the squashed result.
Related Concepts¶
- Git reset
- Git stash
- [[Git merge]]
- Documentation Workflow
Sources¶
600-developer__tools__git__git-command.md