3

I've been hitting git repo corruptions lately. It happened whenever my virtual machine failed to resume from a saved state or error when saving its state. Whenever it happend, some objects became empty (commit, tree, blobs)

To clarify the matter, the other non-git data was ok. Only the data versioned-controlled by git encountered this problem.

I would like to understand on how did the corruption happen in the first place. The object is just a compressed contents,so, how did it become empty even tho it has been saved to the disk?

Also, kindly advice on how to prevent this from happening. I tried to have a local bare repo, but even the bare repo got corrupted. Most of the time I use my Virtual Machine for offline stuff, and dont have net connection. So, external repo is not an option.

Many thanks for any pointer.

kuronue
  • 306
  • 2
  • 8

1 Answers1

2

To avoid this, you can, just before saving the state of your machine, create a full bundle of your current repo (git bundle):

cd /path/to/your/repo
git bundle create ../repo.bundle --all

That way, if you git repo is corrupted, you can clone it back from that one file:

git clone repo.bundle
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. But, bundling it wont keep the un-commited changes. Also, it will become a maintenance headache to bundle everyday. – kuronue Dec 02 '13 at 06:44
  • @kuronue bundle is easily automated, so no maintenance headache there. I will have to test if a bundle --all include the stash. If it does, you can save uncommitted work with `git stash`. – VonC Dec 02 '13 at 07:00