How to fix fatal: invalid sha1 pointer in cache-tree in Git

GitINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 243 views

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
  1. Diagnose the issue with git fsck
  2. Backup your current state
  3. Remove the corrupted index and reset
  4. Verify the fix
git — error
git fsck --full
fatal: 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

  1. Interrupted Git operation (killed process, crash, or power failure during add/commit)
  2. Disk space running out while Git was writing to the index
  3. Filesystem corruption or bad disk sectors affecting .git/index
  4. Bug in a Git GUI client or IDE integration that corrupted the index
  5. Incomplete clone or fetch operation
  6. Network storage or cloud sync tools interfering with .git directory

How to fix "fatal: invalid sha1 pointer in cache-tree"

1Diagnose the issue with git fsck

First, run a full filesystem check to understand the extent of the corruption:

bash
git fsck --full

This 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:

bash
error: d193ccbc48a30e8961e9a2515a708e228d5ea16d: invalid sha1 pointer in cache-tree

This specifically indicates cache-tree corruption in the index file.

2Backup your current state

Before making any changes, backup your .git directory and any uncommitted work:

bash
# Backup the entire .git directory
cp -r .git .git-backup

# If you have uncommitted changes, save them
git stash 2>/dev/null || true

Also note any staged changes you have that you want to preserve:

bash
git diff --cached > staged-changes.patch 2>/dev/null || true
3Remove the corrupted index and reset

The cache-tree is stored in the .git/index file. Removing this file and resetting will regenerate it:

bash
rm .git/index
git reset

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

4Verify the fix

Run git fsck again to confirm the corruption is resolved:

bash
git fsck --full

You should no longer see the "invalid sha1 pointer in cache-tree" error.

Then check that normal operations work:

bash
git status
git log --oneline -5

If everything looks good, you can remove the backup:

bash
rm -rf .git-backup
5Re-stage your changes if needed

If you had staged changes before the corruption, you'll need to re-stage them:

bash
# 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 status

If you used git stash earlier, recover those changes:

bash
git stash pop
6If the error persists: fetch from remote

If the simple index reset doesn't fix the issue and you have a remote repository, you can rebuild local objects from the remote:

bash
# Remove local objects and re-fetch
rm -rf .git/objects/?? .git/objects/pack/*
git fetch --all

# Then reset the index
rm .git/index
git reset

Warning: This removes all local-only commits. Make sure your important commits are pushed to the remote first.

7Last resort: re-clone the repository

If the corruption is extensive and you have a remote:

bash
# 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:

bash
# Install git-repair (Debian/Ubuntu)
sudo apt install git-repair

# Run repair
git-repair

This 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