6.7 Rewriting History

Revisionist historians view history as a living thing—something that needs to be reevaluated from time to time to make sure the assumptions that were made in the past still apply.

Looking over your code as part of a formal code review is a great way to make sure the assumptions you made last week or last month still apply. Git lets you take this a step further, though, by allowing you to not only review the history of your code but to rewrite it.

There are a few instances where this is useful:

  • Reorder the history so it makes more sense: This is the hardest to quantify, but you’ll know it when you see it. One commit, or maybe more, seems out of place and logically fits in a different order.

  • Squash several commits ...

Get Pragmatic Version Control Using Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.