0

I changed all of the line endings in my project from dos mode to unix mode by removing all of the carriage returns from any file that had them:

grep -lIUr '^M' . | xargs sed -i 's/^M//'

I thought that it would ignore hidden dotfiles like .git/, but it didn't, and now my git repository has been mangled.

git fsck

gives

Checking object directories: 100% (256/256), done.
error: inflate: data stream error (incorrect data check)
fatal: loose object 62f7323e2a025640a25214f13a670097876c1683 (stored in .git/objects/62/f7323e2a025640a25214f13a670097876c1683) is corrupt

There aren't any other copies of the repository checked out anywhere. Is there any way to recover from this? Is my repo dead?

Dan Ross
  • 3,596
  • 4
  • 31
  • 60

2 Answers2

1

Yes, it is. No luck, since all ^M are gone: maybe you can partially recover history and build another repo, but nothing more.

For the future, use greater care and proper tools like dos2unix for converting line endings.

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • 1
    I can't believe I forgot about dos2unix. I've never used it, but I have seen it before somewhere. A painful reminder on backups. – Dan Ross May 30 '13 at 23:34
  • For some reason Ubuntu prefers to call it `fromdos` (comes from package strangely named `tofrodos`) - which is of course equivalent to `dos2unix` – mvp May 31 '13 at 08:10
1

In the future (does not help you now), you can limit your command to files in the repository.

grep -lIUr '^M' `git ls-files` | xargs sed -i 's/^M//'
cforbish
  • 8,567
  • 3
  • 28
  • 32