Git Reference ยท Maintenance and Recovery
git commit-graph command
Reference for git commit-graph write and verify: how the commit-graph file speeds up log, merge-base and reachability queries, plus split chains and Bloom filters.
The commit-graph is a compact, binary cache of the commit history. For every commit it stores the tree ID, the parent positions, the commit date and the generation number (how many steps the commit is from the root). Git can then walk history, compute merge bases and answer "is A an ancestor of B?" without opening and parsing each commit object.
git commit-graph writes and checks that file. The file lives at .git/objects/info/commit-graph (or, in split mode, in a chain of files under .git/objects/info/commit-graphs/). The cache never changes the result of a command, only its speed, so it is safe to delete and rebuild. Git already writes it during git gc and, with fetch.writeCommitGraph, after fetches.
git commit-graph write --reachable
git commit-graph verify
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git commit-graph verify [--object-dir <dir>] [--shallow] [--[no-]progress] git commit-graph write [--object-dir <dir>] [--append] [--split[=<strategy>]] [--reachable | --stdin-packs | --stdin-commits] [--changed-paths | --no-changed-paths] [--max-new-filters <n>] [--[no-]progress] <split options>
| Name | Description |
|---|---|
write |
Create or replace the commit-graph. With no source option it includes the commits found in the existing graph and in pack indexes. |
verify |
Check that the file is well formed and that its data matches the real commits. --shallow checks only the top layer of a chain. |
--reachable |
Include every commit reachable from any ref. This is the usual choice. |
--stdin-commits |
Read commit IDs from standard input (one per line) and include those and their ancestors. |
--stdin-packs |
Read pack index names from standard input and include the commits in those packs. |
--append |
Keep the commits already in the graph and add the new ones. |
--split[=<strategy>] |
Write an incremental layer instead of rewriting everything. Strategies: no-merge (never merge layers) and replace (always write one graph). |
--changed-paths |
Also store a Bloom filter per commit, which records which paths the commit changed. Speeds up git log -- <path> and git blame. |
--no-changed-paths |
Do not write Bloom filters and drop existing ones. |
--max-new-filters <n> |
Compute at most n new Bloom filters in this run. |
--size-multiple, --max-commits, --expire-time |
Tuning options for how split layers are merged and when old layers are deleted. |
--object-dir <dir> |
Use a different object directory, for example an alternate. |
Returns: nothing on success. verify exits non-zero and prints the mismatching data when the file is corrupt.
Usage notes
- Pure cache. If the file is missing or damaged, Git silently falls back to reading commits. Deleting
.git/objects/info/commit-graph*is always safe. Disable use of the file withcore.commitGraph=false. - Generation numbers let
git log --graph,git merge-baseandgit branch --containsstop early instead of walking to the root. The benefit grows with history size: on a repository with a million commits,git tag --containscan go from minutes to seconds. - Bloom filters answer "might this commit have touched this path?" in constant time, so a path-limited log skips most commits without reading trees. Filters can give false positives (Git then checks the real tree) but never false negatives.
- Automatic writing.
gc.writeCommitGraph(default true) writes it ingit gc;fetch.writeCommitGraphwrites a split graph after fetch;git maintenancehas acommit-graphtask for background upkeep. See git maintenance and gc configuration. - Shallow clones and grafts. The file is not used when the repository is shallow or has replace refs or grafts that change parents, because cached parents would be wrong.
- Hash algorithm. A commit-graph is tied to the repository's object format (SHA-1 or SHA-256). See The commit-graph format.
- Untrusted writes. Do not edit the file by hand. Rebuild it with
writeinstead.