Git 允许您重写历史 — 修改、变基、压缩或删除提交 — 以清理提交或修复问题。这很强大但必须小心进行:重写共享历史会导致严重问题,所以围绕它的规则至关重要。
重写历史的方式
git commit --amend → modify the most recent commit (message or content)
git rebase -i → squash, reword, reorder, edit, drop commits (interactive)
git rebase <branch> → replay commits onto another base (linear history)
git reset → move the branch pointer (discard/uncommit)
git filter-repo → rewrite MANY commits (remove a file/secret from all history)
→ All of these change commit HASHES (rewriting = creating new, different commits).
