LinuxCommandLibrary

git-commit-graph

Improve Git repository commit history performance

TLDR

Write a commit-graph file for the packed commits in the repository's local .git directory

$ git commit-graph write
copy

Write a commit-graph file containing all reachable commits
$ git show-ref [[-s|--hash]] | git commit-graph write --stdin-commits
copy

Write a commit-graph file containing all commits in the current commit-graph file along with those reachable from HEAD
$ git rev-parse [HEAD] | git commit-graph write --stdin-commits --append
copy

SYNOPSIS

git commit-graph write|verify [options]

PARAMETERS

write
    Write a new commit-graph file from reachable commits

verify
    Verify integrity of existing commit-graph file(s)

--stdin-commits
    Read newline-delimited commit OIDs from stdin instead of refs

--stdin-packs
    Read pack index files from stdin for traversal

--append
    Append to existing commit-graph (write mode only)

--split
    Write split commit-graph files by size (write mode only)

--shallow
    Limit to commits reachable from shallow refs

--progress
    Show progress (default unless --quiet)

--quiet
    Suppress progress output

--size-multiply N
    Multiply split file size limit by N (default 2)

--max-new-splits N
    Limit new split files to N (default 6)

DESCRIPTION

The git commit-graph command manages commit-graph files, which are supplemental indexes accelerating operations like git log, git status, and git rev-list by providing precomputed topological sorting, parent data, and generation numbers.

In write mode, it traverses reachable commits from refs, builds a sorted list with metadata (parents, generation, root/changed paths bloom filters), and stores it in .git/objects/info/commit-graphs (or split files for large repos).

In verify mode, it checks file integrity, connectivity to the object database, and consistency of metadata.

Commit-graphs reduce history traversal time, especially in large repositories, without altering the object database. They auto-load during operations if present and valid. Use during maintenance like git gc for best results.

CAVEATS

Commit-graphs are read-only after writing; invalidate with rm .git/objects/info/commit-graphs/*. Split mode experimental; large repos may need tuning. Not loaded if verification fails.

FILE LOCATION

.git/objects/info/commit-graphs/; graph-*.graph files, optionally split as graph-{xx}.graph

PERFORMANCE BENEFITS

Speeds up log traversal by 2-10x; enables faster git status with generation numbers; supports changed-paths filtering

HISTORY

Introduced in Git 2.19.0 (June 2018) by Derrick Stolee for performance. Enhanced in 2.20+ with splits, generations, blooms. Now auto-generated by git gc since 2.28.

SEE ALSO

Copied to clipboard