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.
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.
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.
### 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.
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