Chapter Four

History and Rewriting

How Git's history is shaped as a graph, how to rewrite it deliberately with interactive rebase, recover lost commits from the reflog, hunt a regression with bisect, and purge secrets or giant files across an entire repository.

5 topics

This chapter is where Git stops being a sequence of commands and becomes a graph you can read and reshape. It opens with the model — commits as nodes, branches as movable pointers, reachability as the rule that decides what lives and dies — because every operation that follows is a manipulation of that graph. Once you see history this way, rewriting it stops being scary and starts being precise.

The tools here are the advanced, internals-leaning ones: interactive rebase to curate local commits before sharing, the reflog as the undo buffer that recovers "lost" work, bisect to binary-search for the commit that broke the build, and repository-wide rewriting to purge secrets and oversized files. A theme runs through all of it — a rewrite changes hashes and forces collaborators to re-clone, and a leaked secret must be rotated no matter how clean the rewrite.

Rewrite by scope
Amend last commitone commit
Interactive rebaserecent commits
filter-repowhole history

Topics in This Chapter