Video in progress
You have to rewrite the history of a repo used by the whole company (because of a secret or big files). How do you plan it?
I plan it like a deploy: an announcement in advance, a code freeze window, new history with git filter-repo, verification of the result, a force push, everyone cloning again, and blocking pushes from old clones. If it is a secret, rotate it first.
📖 Answer
Rewriting history changes every commit hash. That affects not only developers' local clones but everything that depends on the hashes: open PRs, commit links in Jira, deploy logs, versions based on git describe, submodule pointers, forks.
The plan I draw up:
- Is it needed? If it is a secret, rotation is the main protection and cleaning history is secondary. If it is size, a partial clone or starting from a new repo may be cheaper.
- A rehearsal. On a copy of the repo, run
git filter-repo --path big-dumps/ --invert-paths(or--replace-text), then check the result: build, tests, whether the tags are in the right place. - The announcement. Date, time, duration. People are asked to merge or close their open PRs beforehand.
- The freeze. Pushes are blocked temporarily.
- Execution. The new history is pushed (
--force, all branches and tags), and the old→new hash mapping file is saved (filter-repowrites it to.git/filter-repo/commit-map). - Protection. A pre-receive hook or scanner on the server so that objects with the old hashes do not come back. A single
git push --allfrom an old clone undoes the whole job. - Platform caches. On GitHub/GitLab, old commits may still be reachable through PRs, so clean them up with support.
In a very large organization, it is sometimes simpler to open a new repo and turn the old one into a read-only archive: fewer problems, and the history is in the archive if needed.
Sign up to mark studied questions and save your progress.