How to fix error: object file .git/objects/ab/cd1234 is empty in Git
This error indicates Git object file corruption, typically caused by interrupted operations, system crashes, or filesystem issues. The fix involves removing empty objects and recovering from a remote repository.
Quick fix
Fixes error: object file .git/objects/ab/cd1234 is empty
cp -a .git .git-backup- Back up your .git folder immediately
- Run git fsck to identify all corrupt objects
- Remove all empty object files
- Fetch missing objects from remote
cp -a .git .git-backuperror: object file .git/objects/ab/cd1234 is empty
What this error means
Git stores all repository data (commits, trees, blobs) as objects in the `.git/objects` directory. Each object is identified by its SHA-1 hash and stored in a subdirectory based on the first two characters of that hash. When Git reports an "object file is empty" error, it means one or more of these critical files has zero bytes—the data that should be there is completely missing. This corruption typically occurs when a write operation to the `.git/objects` directory is interrupted before completion. Git normally writes objects to a temporary file first, then renames it atomically, but certain conditions can still leave empty files behind. Common culprits include: - Your laptop running out of battery during a Git operation (commit, fetch, merge) - A virtual machine or container being forcefully stopped - File system bugs, especially with network filesystems (NFS, VirtualBox shared folders, CIFS) - Hard drive failures or filesystem corruption - The system running out of disk space mid-write The good news is that if you have a remote repository (GitHub, GitLab, etc.), you can usually recover completely by fetching the missing objects. If you only have a local repository with no remote, recovery may be partial or impossible depending on which objects were corrupted.
Typical symptoms
- Git commands fail with 'error: object file .git/objects/xx/xxxx is empty'
- Running 'git status' or 'git log' produces corruption errors
- Git operations that worked before suddenly fail after a crash or power loss
- 'git fsck' reports 'error: sha1 file is corrupt' or 'missing object'
- Attempting to checkout, merge, or rebase fails with object errors
Common causes
- System crash or power loss during a Git write operation (most common)
- Virtual machine forcefully stopped while Git was running
- Disk running out of space during Git operations
- Buggy filesystem drivers (VirtualBox vboxsf, NFS, network mounts)
- Hard drive or SSD failure causing filesystem corruption
- Overly aggressive antivirus software interfering with file writes
How to fix "error: object file .git/objects/ab/cd1234 is empty"
Before attempting any repairs, create a backup of your entire .git directory. If something goes wrong during recovery, you'll need this.
cp -a .git .git-backupCreate additional backups after each major step using different names (.git-backup-1, .git-backup-2, etc.).
Use Git's built-in filesystem check to get a complete list of problems:
git fsck --fullThis will report all issues including empty files, corrupt objects, and missing references. Note down any error messages—you may see multiple corrupt objects.
Example output:
error: object file .git/objects/ab/cd1234... is empty
error: object file .git/objects/ef/gh5678... is empty
missing blob abc123...Delete all zero-byte files in the objects directory. Git cannot use these files anyway, and removing them allows Git to fetch fresh copies from the remote.
find .git/objects/ -type f -empty -deleteThis command finds all empty files recursively in .git/objects/ and removes them.
Alternative: Remove a specific corrupt object manually:
rm .git/objects/ab/cd1234...Replace ab/cd1234... with the path shown in the error message.
If you have a remote repository configured, fetch to download the missing objects:
git fetch originThis retrieves all objects from the remote that aren't in your local repository, including replacements for the ones you just deleted.
If you have multiple remotes or need objects from a specific branch:
git fetch --allRun git fsck again to confirm all issues are resolved:
git fsck --fullAt this point, there should be no errors (warnings about dangling objects are usually fine). Test basic operations:
git status
git log --oneline -5If these work without errors, your repository is recovered.
If you're still seeing errors about HEAD or the index after fixing object files, you may need to reset them:
# If HEAD is corrupt
git symbolic-ref HEAD refs/heads/main
# Use 'master' instead of 'main' if that's your default branch
# If the index is corrupt
rm .git/index
git resetThis rebuilds the index from the current HEAD commit.
After recovery, clean up any unreferenced objects:
git pruneThen run a garbage collection to optimize the repository:
git gcThis packs loose objects and removes unreachable ones, which can prevent future issues.
If the above steps don't work, you can replace the entire .git directory from a fresh clone while keeping your working directory changes:
# Save your current work
git stash --include-untracked 2>/dev/null || true
# Clone fresh in a different location
git clone <remote-url> ../repo-fresh
# Replace .git directory
rm -rf .git
mv ../repo-fresh/.git .
# Verify and check status
git statusThis gives you a clean repository state. Any uncommitted changes in your working directory will appear as modifications that you can review and commit.
Advanced notes
### Why This Happens
Git objects are the fundamental storage units—blobs contain file content, trees represent directories, and commits point to trees with metadata. When any of these becomes empty or corrupt, Git cannot reconstruct the repository state.
Git is designed to be resilient: it writes to temporary files then renames them atomically. However, this protection can fail when:
1. Filesystem bugs: VirtualBox shared folders (vboxsf) and some network filesystems don't guarantee atomic renames
2. Disk caching: If the OS caches writes and power fails before flushing, data is lost
3. Insufficient permissions: If Git can't complete a rename, the temporary file may be left behind
### Prevention
Consider enabling core.fsyncobjectfiles for critical repositories:
git config core.fsyncobjectfiles trueThis forces Git to fsync each object file, ensuring it's written to disk before continuing. This is slower but safer.
### Using git-repair Tool
For complex corruption, the git-repair tool can automate many recovery steps:
# Install (Debian/Ubuntu)
sudo apt install git-repair
# Run repair
git-repairThis tool attempts various recovery strategies automatically.
### When Recovery Fails
If you don't have a remote and critical objects are corrupted:
1. Check for backups (Time Machine, system backups)
2. Use git unpack-objects with a packfile from any working clone
3. As a last resort, git init a new repository and copy your working tree—you'll lose history but keep current files
### Reflog as Recovery Source
Sometimes git reflog contains references to commits that can help recovery:
git reflogIf you see the commit you need, try checking it out directly by SHA.
Frequently asked questions
- What does "error: object file .git/objects/ab/cd1234 is empty" mean?
- git/objects directory. Each object is identified by its SHA-1 hash and stored in a subdirectory based on the first two characters of that hash. When Git reports an "object file is empty" error, it means one or more of these critical files has zero bytes—the data that should be there is completely missing.
- How do I fix "error: object file .git/objects/ab/cd1234 is empty"?
- This error indicates Git object file corruption, typically caused by interrupted operations, system crashes, or filesystem issues. The fix involves removing empty objects and recovering from a remote repository.
- What causes "error: object file .git/objects/ab/cd1234 is empty"?
- System crash or power loss during a Git write operation (most common) Virtual machine forcefully stopped while Git was running Disk running out of space during Git operations
- Is the "error: object file .git/objects/ab/cd1234 is empty" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚Git Official Documentation
- 💬
- 💬Git: Corrupt loose object - Stack Overflow(Stack Overflow)
- 💬How do I deal with corrupted Git object files? - Stack Overflow(Stack Overflow)
- 📖git-fsck Documentation - Git(Official Docs)
- 💬Git Cookbook - Repairing and recovering broken git repositories(Stack Overflow)
- 💬Repair git says object files are empty/corrupted - GitHub Gist(Stack Overflow)
- 📖How-To: Fix Missing or Corrupt Git Objects - GitLab(Official Docs)