2

I had a git repo in a Dropbox folder for quite some time. Now it is corrupted. (Never put git repos in Dropbox!) I deleted a few empty objects files. Now, a git fsck shows a list of broken links, dangling blobs, and missing trees.

However, I'm pretty sure that my working copy is fine. So at least the current state can be saved, but I may lose some history.

Is it possible to let git remove broken commits?

Is it possible that the missing stuff can be repopulated from the working copy or would git notice that?

qznc
  • 1,113
  • 2
  • 12
  • 25
  • Don't you still have a local copy of the repository? (I mean the whole repository, not just the working copy) – mkrieger1 Feb 17 '17 at 14:39
  • Yes, I have the local copy which is broken. I have no repo with the full history anymore. – qznc Feb 17 '17 at 14:51

1 Answers1

2

I deleted a few empty objects files

That seems a bad idea to start with... You could use your dropbox history to restore those deleted objects.

I have little experience with broken commits.Depending on what you want to do there are multiple options:

1. never mind about the history; I just want to get up and running again with git

A fast and easy approach to restore your git repository but lose all you history is just removing the git directory and starting all over again:

rm -rf .git
git init
git commit -am "initial commit"

2. I still have part of the history; and that suffices for me

try cloning your repository; probably you will keep the part of the history that is still intact.

3. I want to recover everything possible from the history

That's a little too advanced for me; take a look here: How to fix corrupted git repository?

Community
  • 1
  • 1
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • 2
    Better create a new repository separately than deleting the old one - chances are that it might be salvaged. – mkrieger1 Feb 17 '17 at 14:41
  • Dropbox history is no help. I use the free Dropbox plan. The misses were too long ago. – qznc Feb 17 '17 at 14:44
  • @qznc I edited my answer. Did you try cloning your repository? – Chris Maes Feb 17 '17 at 14:52
  • Cloning with depth helped. Thanks for the link to http://stackoverflow.com/a/29303015/2361979 Now I have the last 250 of 618 commits at least. – qznc Feb 17 '17 at 14:56
  • Also, to unshallow forcefully, I needed http://stackoverflow.com/a/38281491/2361979 – qznc Feb 17 '17 at 15:32