This error occurs when git rev-list encounters a missing, corrupted, or invalid object (commit, blob, or tree) in the repository. It typically indicates repository corruption or incomplete data transfer.
The git rev-list command is used internally by Git to list commit objects in reverse chronological order. When it encounters a "bad object" or "invalid object" error, it means Git is trying to access an object (commit, tree, or blob) that is either missing from the object database, corrupted, or has an invalid SHA-1 hash. This error commonly appears during operations like git push, git fetch, git clone, or git log when Git needs to traverse the commit history. The object database in .git/objects stores all repository data, and when objects are missing or corrupted, Git cannot complete operations that need to read those objects. Repository corruption can occur due to incomplete clone/fetch operations, interrupted push/pull transfers, filesystem errors, disk corruption, aggressive garbage collection, or cloud sync conflicts (OneDrive, iCloud). Force pushes with Git LFS can also trigger this error if objects aren't properly synchronized.
Run a full filesystem check to identify all missing or corrupt objects:
git fsck --full --strictThis will output all integrity issues. Note the object types (blob, tree, commit) and their hashes. If you see "missing blob", "missing tree", or "dangling commit", the repository has lost data.
For detailed output:
git fsck --full --strict --verboseIf you have a remote repository (origin), attempt to fetch the missing objects:
# Remove empty object files that may cause issues
find .git/objects/ -type f -empty -delete
# Fetch all objects from remote
git fetch -p origin
# Or fetch all refs
git fetch --allThis works when the corruption is local and the remote has complete data. After fetching, run git fsck --full again to verify.
If you have another clone of the repository or a backup, you can copy missing objects:
# Clone a fresh copy to /tmp
git clone <remote-url> /tmp/fresh-repo
# Add it as an alternate object store
echo "/tmp/fresh-repo/.git/objects/" > .git/objects/info/alternates
# Repack to copy missing objects
git repack -a -d
# Remove the alternate
rm .git/objects/info/alternatesAlternatively, directly copy missing objects from the fresh clone:
rsync -av /tmp/fresh-repo/.git/objects/ .git/objects/If specific branches are corrupt, you may need to reset their references:
# Find the last known good commit
git log --all --oneline | head -20
# Update the branch reference to a good commit
git update-ref refs/heads/main <good-commit-hash>
# Ensure HEAD points to the correct branch
git symbolic-ref HEAD refs/heads/mainTo delete corrupt empty refs:
find .git/refs -size 0 -delete -printIf the repository is severely corrupted and you have uncommitted work:
# Save your working tree changes
cp -r your-broken-repo your-broken-repo-backup
# Clone fresh copy
git clone <remote-url> your-repo-fixed
# Copy your working files (NOT .git) from backup
cp -r your-broken-repo-backup/* your-repo-fixed/
# Review and commit changes
cd your-repo-fixed
git status
git add .
git commit -m "Restore work after corruption"This gives you a clean repository with your latest changes preserved.
On Linux systems, git-repair can automatically fix many corruption issues:
# Install git-repair
sudo apt install git-repair # Debian/Ubuntu
# Run repair from repository root
cd /path/to/repo
git-repair
# Clean up broken refs
find .git/refs -size 0 -delete -print
# Verify
git fsck --fullgit-repair will attempt to recover from backups and rebuild corrupt structures automatically.
Repository corruption prevention: Never store Git repositories in cloud-synced folders (OneDrive, Dropbox, iCloud) as file locking and sync conflicts can corrupt objects. Use dedicated Git hosting instead. On Windows, enable long path support with git config --system core.longpaths true to prevent path-related corruption.
If the .git/objects directory is completely lost or unrecoverable, the repository data is gone. In this case, delete the .git folder, run git init, and start fresh, optionally pulling from remote if available.
For repositories with Git LFS, ensure LFS objects are properly synced before force-pushing. Use git lfs fetch --all before operations that rewrite history.
When fsck reports "dangling" objects, these are usually harmless - they're unreachable objects from rebases, amended commits, or deleted branches. You can remove them with git gc --prune=now after confirming no data is needed.
For CI/CD systems encountering this error, check that shallow clones (--depth) aren't causing issues. Some operations require full history. Use git fetch --unshallow to convert shallow clones to full clones.
fatal: Out of memory, malloc failed during pack operation
Out of memory during Git pack operation
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