The 'multi-pack-index verification failed' error occurs when Git's MIDX file becomes corrupted or out of sync with the actual pack files. Regenerating the multi-pack-index typically resolves the issue.
This error indicates that Git's multi-pack-index (MIDX) file has failed its integrity check. The multi-pack-index is an optimization feature introduced in Git that creates a single index across multiple pack files, improving performance when your repository has many packs. When Git verifies the MIDX file (either explicitly via `git multi-pack-index verify` or during normal operations), it checks that the index correctly references all objects in the associated pack files. If this verification fails, it usually means the MIDX file has become corrupted or fallen out of sync with the actual pack files. Common scenarios that cause this corruption include: 1. **Interrupted operations** - A `git gc`, `git repack`, or similar operation was interrupted (system crash, killed process) 2. **Race conditions** - Multiple Git processes modified pack files simultaneously, especially during `git repack -ad` 3. **File system issues** - Disk errors, network storage problems, or sync issues in cloud-backed directories 4. **Git version bugs** - Older Git versions (before 2.36) had bugs that could cause MIDX and bitmap data to become out of sync
Before making changes, run diagnostics to understand the scope of the problem:
# Run full repository verification
git fsck --full
# Specifically verify the multi-pack-index
git multi-pack-index verify
# Check the status of pack files
ls -la .git/objects/pack/
# Look for the MIDX file
ls -la .git/objects/pack/multi-pack-indexThis helps determine if the issue is isolated to the MIDX or if there's broader repository corruption.
The simplest fix is to delete the corrupted MIDX file and regenerate it:
# Remove the corrupted multi-pack-index file
rm .git/objects/pack/multi-pack-index
# Regenerate the multi-pack-index
git multi-pack-index writeIf the write command succeeds, verify the new index:
git multi-pack-index verifyThis should complete without errors if the underlying pack files are intact.
If regenerating the MIDX fails, the underlying pack files may need to be rebuilt:
# First, disable multi-pack-index temporarily
git config core.multiPackIndex false
# Repack all objects into a fresh pack file
git repack -a -d -f
# Re-enable multi-pack-index
git config core.multiPackIndex true
# Write a new multi-pack-index
git multi-pack-index writeThe git repack -a -d -f command:
- -a - Pack all objects into one pack
- -d - Delete old pack files after repacking
- -f - Force recreation even if pack already exists
After rebuilding, run garbage collection to clean up any remaining issues:
# Run garbage collection
git gc
# Or more aggressive cleanup
git gc --aggressive --prune=nowThe --aggressive flag spends more time optimizing the repository, which can help ensure consistency.
Note: On large repositories, git gc --aggressive can take a very long time. For most cases, a regular git gc is sufficient.
If the repository remains corrupted after the above steps, re-cloning may be the safest option:
# Move the old repository aside
mv myrepo myrepo.backup
# Clone fresh from remote
git clone <remote-url> myrepo
# Copy any uncommitted work from backup
# Check for unstaged changes in backup first
cd myrepo.backup
git status
git stash listBefore deleting the backup:
1. Verify all branches exist in the fresh clone
2. Check that uncommitted changes have been recovered
3. Ensure any local-only branches are pushed to remote
If you continue to experience MIDX problems, you can disable the feature entirely:
# Disable multi-pack-index globally
git config --global core.multiPackIndex false
# Remove any existing MIDX files
rm .git/objects/pack/multi-pack-index
rm .git/objects/pack/*.bitmap # Also remove associated bitmapsThis sacrifices some performance optimization but ensures stability. You can re-enable it later:
git config --global core.multiPackIndex true
git multi-pack-index writeNote: Disabling MIDX may impact performance on repositories with many pack files.
### Understanding Multi-Pack-Index (MIDX)
The multi-pack-index is a Git feature that improves performance when dealing with multiple pack files. Instead of searching each pack file individually, Git can use a single index that spans all packs.
The MIDX file is stored at .git/objects/pack/multi-pack-index and contains:
- A list of all indexed pack files
- Object ID to pack-file offset mappings
- Optional bitmap data for reachability queries
### Known Race Condition with git repack
There's a documented race condition where git repack -ad can cause MIDX verification failures:
1. Process A reads the MIDX to find object locations
2. Process B runs git repack -ad, deleting old packs and creating new ones
3. Process A tries to access an object in a now-deleted pack
4. Verification fails because the MIDX references non-existent packs
This was partially addressed in Git 2.22+ but can still occur in certain scenarios.
### Git Version Considerations
- Git 2.20 - Introduced basic multi-pack-index support
- Git 2.22 - Added expire and repack subcommands
- Git 2.36 - Fixed bugs causing MIDX and bitmap desynchronization
If experiencing frequent MIDX issues, consider upgrading Git:
# Check current version
git --version
# Update on Ubuntu/Debian
sudo add-apt-repository ppa:git-core/ppa
sudo apt update && sudo apt install git
# Update on macOS
brew upgrade git
# Update on Windows
git update-git-for-windows### Server-Side MIDX Issues
On Git servers hosting large repositories, MIDX problems can impact multiple users. Consider:
# Schedule maintenance during low-activity periods
git gc --auto
# Use incremental repack for minimal disruption
git multi-pack-index repack --batch-size=0
# Expire old packs after repack
git multi-pack-index expire### Monitoring Repository Health
Set up periodic verification to catch issues early:
# Add to cron or scheduled task
git fsck --connectivity-only # Quick check
git multi-pack-index verify # MIDX-specific check### Cloud Storage and Network File Systems
MIDX corruption is more common on:
- Network-mounted file systems (NFS, SMB)
- Cloud-synced directories (Dropbox, OneDrive, Google Drive)
- Repositories on external drives
For these scenarios, consider keeping core.multiPackIndex disabled or ensuring proper file locking is in place.
### Recovering Lost Objects
If objects were lost due to corruption:
# Check reflog for recent commits
git reflog
# Attempt to recover dangling objects
git fsck --lost-found
ls .git/lost-found/
# Objects here can potentially be restored
git cat-file -t <object-sha> # Check object type
git cat-file -p <object-sha> # Print object contentskex_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