How to fix error: object file .git/objects/ab/cd1234 is empty in Git

GitINTERMEDIATEHIGHUpdated Dec 6, 2025· 160 views

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
  1. Back up your .git folder immediately
  2. Run git fsck to identify all corrupt objects
  3. Remove all empty object files
  4. Fetch missing objects from remote
git — error
cp -a .git .git-backup
error: 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

  1. System crash or power loss during a Git write operation (most common)
  2. Virtual machine forcefully stopped while Git was running
  3. Disk running out of space during Git operations
  4. Buggy filesystem drivers (VirtualBox vboxsf, NFS, network mounts)
  5. Hard drive or SSD failure causing filesystem corruption
  6. Overly aggressive antivirus software interfering with file writes

How to fix "error: object file .git/objects/ab/cd1234 is empty"

1Back up your .git folder immediately

Before attempting any repairs, create a backup of your entire .git directory. If something goes wrong during recovery, you'll need this.

bash
cp -a .git .git-backup

Create additional backups after each major step using different names (.git-backup-1, .git-backup-2, etc.).

2Run git fsck to identify all corrupt objects

Use Git's built-in filesystem check to get a complete list of problems:

bash
git fsck --full

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

bash
error: object file .git/objects/ab/cd1234... is empty
error: object file .git/objects/ef/gh5678... is empty
missing blob abc123...
3Remove all empty object files

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.

bash
find .git/objects/ -type f -empty -delete

This command finds all empty files recursively in .git/objects/ and removes them.

Alternative: Remove a specific corrupt object manually:

bash
rm .git/objects/ab/cd1234...

Replace ab/cd1234... with the path shown in the error message.

4Fetch missing objects from remote

If you have a remote repository configured, fetch to download the missing objects:

bash
git fetch origin

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

bash
git fetch --all
5Verify the repository is repaired

Run git fsck again to confirm all issues are resolved:

bash
git fsck --full

At this point, there should be no errors (warnings about dangling objects are usually fine). Test basic operations:

bash
git status
git log --oneline -5

If these work without errors, your repository is recovered.

6Fix HEAD or index corruption (if needed)

If you're still seeing errors about HEAD or the index after fixing object files, you may need to reset them:

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

This rebuilds the index from the current HEAD commit.

7Run git prune to clean up (optional)

After recovery, clean up any unreferenced objects:

bash
git prune

Then run a garbage collection to optimize the repository:

bash
git gc

This packs loose objects and removes unreachable ones, which can prevent future issues.

8Alternative: Replace .git from a fresh clone

If the above steps don't work, you can replace the entire .git directory from a fresh clone while keeping your working directory changes:

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

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

bash
git config core.fsyncobjectfiles true

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

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

# Run repair
git-repair

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

bash
git reflog

If 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