This error occurs when Git's commit-graph cache file becomes corrupted. The commit-graph is a performance optimization that can be safely deleted and regenerated without data loss.
The "commit-graph is corrupt" error indicates that Git's commit-graph file has become damaged or inconsistent. The commit-graph is an optional performance feature introduced in Git 2.18 that caches commit ancestry information to speed up operations like `git log --graph`, reachability queries, and other commit traversals. The commit-graph file is stored at `.git/objects/info/commit-graph` (or in `.git/objects/info/commit-graphs/` for split graphs). When Git detects corruption in this file - such as invalid commit positions, bad checksums, or references to non-existent commits - it reports this error. Importantly, the commit-graph is purely a cache. Your actual repository data (commits, trees, blobs) remains intact in the object database. Deleting and regenerating the commit-graph will not cause any data loss - it will only temporarily slow down certain operations until the cache is rebuilt.
First, confirm that the commit-graph is actually corrupt:
git commit-graph verifyThis command checks the commit-graph file against the object database. If corrupt, you'll see output like:
error: commit-graph is corruptYou can also run a full repository check:
git fsck --fullIf core.commitGraph is enabled (the default in modern Git), fsck will also verify the commit-graph.
The commit-graph is a cache file that can be safely deleted. Remove it:
# Remove the main commit-graph file
rm -f .git/objects/info/commit-graph
# Also remove split commit-graph files if they exist
rm -rf .git/objects/info/commit-graphs/After deletion, Git will fall back to computing commit ancestry from the object database directly. Operations may be slower until you regenerate the graph.
Rebuild the commit-graph from scratch:
git commit-graph write --reachableThis scans all reachable commits and builds a new, valid commit-graph file. For large repositories, this may take a few minutes.
To also include generation numbers (improves performance):
git commit-graph write --reachable --changed-pathsVerify the new graph is valid:
git commit-graph verifyYou should see no output if the graph is healthy.
After regenerating the commit-graph, run garbage collection to ensure consistency:
git gcThis will also regenerate the commit-graph if needed. For a more thorough cleanup:
git gc --aggressive --prune=nowNote: --aggressive is slower but produces better compression.
If you continue to experience problems, you can temporarily disable the commit-graph:
# Disable commit-graph for this repository
git config core.commitGraph false
# Or disable globally
git config --global core.commitGraph falseThis tells Git not to use the commit-graph cache, falling back to the object database. Operations will be slower on large repositories but should work reliably.
To re-enable after fixing issues:
git config core.commitGraph true
git commit-graph write --reachableCommit-graph corruption often occurs when Git repositories are stored in cloud-synced folders:
For cloud storage (OneDrive, Dropbox, iCloud, Google Drive):
- Move your Git repositories outside of synced folders
- Or exclude .git directories from syncing
For OneDrive on Windows:
# Check if OneDrive is causing lock issues
Get-ChildItem -Path .git -Recurse -Filter "*.lock"For network filesystems (NFS, CIFS, SMB):
These can cause synchronization issues. Consider using local storage for active development.
Check for lock files:
# Remove stale lock files
rm -f .git/objects/info/commit-graph.lockUnderstanding the Commit-Graph: The commit-graph is a binary file that stores commit OIDs, parent relationships, commit dates, and generation numbers. It uses a chunked format with sections like OID Fanout (OIDF), OID Lookup (OIDL), Commit Data (CDAT), and optionally Generation Data (GDA2). The format has evolved across Git versions, which can cause compatibility issues.
Split Commit-Graphs: Git 2.31+ supports split commit-graphs stored in .git/objects/info/commit-graphs/. These allow incremental updates without rewriting the entire graph. To merge split graphs:
git commit-graph write --reachable --split=merge-allGeneration Data Corruption: Git 2.38 fixed a bug where older versions wrote incorrect data in GDA2 (Generation Data) and GDO2 (Generation Data Overflow) chunks. If you downgrade from Git 2.38+, you may encounter issues. The fix renamed the chunks to include "2" in their IDs to distinguish from the erroneous data.
Preventing Future Corruption:
# Enable automatic maintenance (Git 2.30+)
git maintenance start
# This schedules regular gc and commit-graph updates
# Check the schedule:
git config --get-all maintenance.scheduleGitLab/Server Environments: For GitLab Docker installations, regenerate with:
git -C /var/opt/gitlab/git-data/repositories/@hashed/<path>.git commit-graph write --reachableChecking Object Existence: If you see errors about commits not existing in the object database, your commit-graph may reference garbage-collected commits. This can happen if core.commitGraph was enabled but objects were pruned without updating the graph:
# Check for stale commit references
git config fetch.writeCommitGraph false
git gc --prune=now
git commit-graph write --reachable
git config fetch.writeCommitGraph truePerformance Impact: On large repositories (100K+ commits), the commit-graph can speed up git log --graph by 10-100x. If you've disabled it due to corruption, regenerating it is worthwhile for performance.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git