Squash
一句话解释
Squashing 组合多个提交到 单个提交, 经常 used 之前合并到 keep history clean.
用大白话说
Squashing combines several commits into one. It is commonly used when a feature branch has many small "工作 in progress" commits that should become a single clean commit when merged into main.
There are two main ways to squash: (1) git rebase -i (interactive rebase) lets you mark commits as "squash" to combine them, and (2) GitHub's "Squash and 合并" button on pull requests automatically squashes all PR commits into one.
Squashing keeps the main branch history clean — one commit per feature or PR instead of many small commits. The trade-off is that the granular history of how the feature was developed is lost. Some teams prefer to keep all commits for traceability; others prefer squashed history for readability.
示例
# Interactive rebase to squash
git rebase -i main
# In the editor, change 'pick' to 'squash' for commits to combine:
# pick abc123 First commit
# squash def456 Second commit
# squash ghi789 Third commit
# Save and edit the combined commit messageInteractive rebase 使用 'squash' 组合提交到 one.
相关术语
相关资源
相关课程
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。