How to fix fatal: invalid sha1 pointer in cache-tree in Git
This error indicates corruption in Git's index cache-tree extension, typically caused by interrupted operations or disk issues. The fix usually involves removing the corrupted index and resetting.
Quick fix
Fixes fatal: invalid sha1 pointer in cache-tree
git fsck --full- Diagnose the issue with git fsck
- Backup your current state
- Remove the corrupted index and reset
- Verify the fix
git fsck --fullfatal: invalid sha1 pointer in cache-tree
What this error means
The Git index (also known as the staging area or cache) contains an extension called the "cache-tree" that stores references to tree objects corresponding to directories in your repository. This extension is an optimization that speeds up commit creation by caching which tree objects have already been computed for unchanged directories. When Git reports "invalid sha1 pointer in cache-tree," it means the cache-tree extension contains a reference to a tree object that doesn't exist or has an invalid SHA-1 hash (like all zeros). This corruption doesn't affect your actual files or commit history—it only affects the index's internal caching mechanism. Common causes include interrupted Git operations (such as a killed `git add` or `git commit`), filesystem corruption, disk space running out during Git operations, or bugs in Git clients or GUI tools. The good news is this type of corruption is usually easy to fix because the cache-tree can be regenerated from your working directory and commits.
Typical symptoms
- Running git fsck --full shows 'invalid sha1 pointer in cache-tree' errors
- Git commands like git status, git add, or git commit fail with fatal errors
- Error message may include a SHA-1 hash like '0000000000000000000000000000000000000000'
- Repository operations become slow or hang unexpectedly
- Git GUI tools report repository corruption or fail to open the repository
Common causes
- Interrupted Git operation (killed process, crash, or power failure during add/commit)
- Disk space running out while Git was writing to the index
- Filesystem corruption or bad disk sectors affecting .git/index
- Bug in a Git GUI client or IDE integration that corrupted the index
- Incomplete clone or fetch operation
- Network storage or cloud sync tools interfering with .git directory
How to fix "fatal: invalid sha1 pointer in cache-tree"
First, run a full filesystem check to understand the extent of the corruption:
git fsck --fullThis will show all corrupted objects. If you only see "invalid sha1 pointer in cache-tree" errors (not broken links or missing objects), the fix is straightforward.
Look for output like:
error: d193ccbc48a30e8961e9a2515a708e228d5ea16d: invalid sha1 pointer in cache-treeThis specifically indicates cache-tree corruption in the index file.
Before making any changes, backup your .git directory and any uncommitted work:
# Backup the entire .git directory
cp -r .git .git-backup
# If you have uncommitted changes, save them
git stash 2>/dev/null || trueAlso note any staged changes you have that you want to preserve:
git diff --cached > staged-changes.patch 2>/dev/null || trueThe cache-tree is stored in the .git/index file. Removing this file and resetting will regenerate it:
rm .git/index
git resetThe git reset command rebuilds the index from your current HEAD commit. Your working directory files remain unchanged—only the staging area is reset.
After running these commands, any previously staged changes will be unstaged, but your files themselves are untouched.
Run git fsck again to confirm the corruption is resolved:
git fsck --fullYou should no longer see the "invalid sha1 pointer in cache-tree" error.
Then check that normal operations work:
git status
git log --oneline -5If everything looks good, you can remove the backup:
rm -rf .git-backupIf you had staged changes before the corruption, you'll need to re-stage them:
# If you saved a patch earlier
git apply staged-changes.patch
# Or manually re-add your changes
git add -A
# Check what will be committed
git statusIf you used git stash earlier, recover those changes:
git stash popIf the simple index reset doesn't fix the issue and you have a remote repository, you can rebuild local objects from the remote:
# Remove local objects and re-fetch
rm -rf .git/objects/?? .git/objects/pack/*
git fetch --all
# Then reset the index
rm .git/index
git resetWarning: This removes all local-only commits. Make sure your important commits are pushed to the remote first.
If the corruption is extensive and you have a remote:
# Save any local changes
cd ..
mv my-repo my-repo-corrupted
# Fresh clone
git clone <remote-url> my-repo
cd my-repo
# Copy over any uncommitted changes from the corrupted repo
# (manually copy files, don't copy .git directory)This gives you a completely fresh repository state while preserving your working files.
Advanced notes
### Understanding the Cache-Tree Extension
The cache-tree is an optional extension in the Git index (documented in the Git index format specification). It stores tree object references for subdirectories that haven't changed, allowing Git to skip recomputing tree objects during commits.
When a file in a directory changes, Git invalidates that directory's cache-tree entry (marked with -1 count). During the next commit, Git recomputes only the invalidated trees rather than the entire tree structure.
### Using git-repair Tool
For severely corrupted repositories, the git-repair tool (from git-annex) can automate recovery:
# Install git-repair (Debian/Ubuntu)
sudo apt install git-repair
# Run repair
git-repairThis tool will delete corrupt objects, fetch missing objects from remotes, and can reset branches if needed.
### Preventing Future Corruption
- Avoid killing Git processes mid-operation
- Ensure adequate disk space before large operations
- Be cautious with cloud sync tools (Dropbox, OneDrive) syncing the .git directory
- Consider using Git hooks to verify index integrity after operations
- On unreliable storage, run git fsck periodically as part of maintenance
### When to Worry
The cache-tree corruption is usually benign—it affects performance optimizations, not your actual data. However, if git fsck shows other errors like "broken link" or "missing object," those indicate more serious corruption that may require recovering objects from a backup or remote.
Frequently asked questions
- What does "fatal: invalid sha1 pointer in cache-tree" mean?
- The Git index (also known as the staging area or cache) contains an extension called the "cache-tree" that stores references to tree objects corresponding to directories in your repository. This extension is an optimization that speeds up commit creation by caching which tree objects have already been computed for unchanged directories. When Git reports "invalid sha1 pointer in cache-tree," it means the cache-tree extension contains a reference to a tree object that doesn't exist or has an invalid SHA-1 hash (like all zeros).
- How do I fix "fatal: invalid sha1 pointer in cache-tree"?
- This error indicates corruption in Git's index cache-tree extension, typically caused by interrupted operations or disk issues. The fix usually involves removing the corrupted index and resetting.
- What causes "fatal: invalid sha1 pointer in cache-tree"?
- Interrupted Git operation (killed process, crash, or power failure during add/commit) Disk space running out while Git was writing to the index Filesystem corruption or bad disk sectors affecting .git/index
- Is the "fatal: invalid sha1 pointer in cache-tree" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Git Official Documentation
- 📖Git - Index Format Documentation(Official Docs)
- 📖Git - git-fsck Documentation(Official Docs)
- 💬
- 💬How can I fix a corrupted Git repository? - Stack Overflow(Stack Overflow)
- 💬
- 💬Restore Corrupt Git Repository - Vincent Tam's Blog(Stack Overflow)
- 🐙
- 📖Git cache-tree.c source code - GitHub(Official Docs)