23. Do not rewrite commits others have
Rewriting replaces commits others may have built on; their merge brings the abandoned commits back; rewrite only commits nobody else has built on.
It is the one rule that keeps rewriting safe for a team.
Rebase and amend make new commits and abandon the old ones. On your own machine, that is fine.
But if someone pulled the old commits, their work is built on top of them.
You push the rewritten ones. Now their history and yours disagree about commits that look the same.
They have to merge the two, and the abandoned commits come back. Twice the history. Easy to get wrong.
The rule: rewrite only commits nobody else has built on. Once others have them, add a new commit instead.
Check yourself. You amended a commit that others have already pulled. What is the safe alternative?
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime