Back to articles
How to Recover from a Corrupted Git Repository

How to Recover from a Corrupted Git Repository

via Dev.toAlan West

There's a special kind of dread that hits when you run git status and get back something like fatal: bad object HEAD or error: object file is empty . Your stomach drops. Your commit history — weeks of work — feels like it just vanished. I've been there three times in eight years. Twice from disk failures, once from a VM that got killed mid-push. Every time, I thought I'd lost everything. Every time, I was wrong. Git is surprisingly resilient, and most "corrupted" repos are fully recoverable if you know where to look. Why Git Repositories Get Corrupted Before we fix anything, it helps to understand what actually broke. Git stores everything as objects in .git/objects/ — blobs (file contents), trees (directories), commits, and tags. Each object is named by its SHA-1 hash and compressed with zlib. Corruption usually happens when: Disk failure or power loss interrupts a write to .git/objects/ A process gets killed during git gc , git repack , or a push/pull Filesystem bugs (more common on

Continue reading on Dev.to

Opens in a new tab

Read Full Article
6 views

Related Articles