Re: How to recovery a corrupted git repo

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: How to recovery a corrupted git repo

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:50:37

Axel Freyn [off-list ref] writes:
I don't know whether there is a single git command to do it, but you can
copy those 5 objects "by hand": in your backup, you should have a
directory .git/objects, where you have the files
   b7/1eb55f2dbc97dafd4a769fc61f346e69a5e0af
   28/2035f3ae964e1e288f352c370be8edd11d3078
   3c/20f556eecc476e3542cc522d46a62a4461fec6
   f3/21b578edeb452358497e832815d6cae6b36886
   6d/23f5084c975be637f7d748db82116bf84d3872

It should be sufficient to just copy those files into the corrupted
repo.

However if you packed the git-files in the backup (e.g. by running "git
gc"), those objects might be found in a pack in .git/objects/pack.
The easiest ist probably to use git-unpack-objects to unpack the
objects, and then copy the 5 missing objects.
There's also the brute-force approach

rsync $good_repo/.git/objects/ $bad_repo/.git/objects/
cd $bad_repo
git gc

Notice the absence of --delete in the rsync command: I'm just adding
new files in the $bad_repo, not deleting any (since files with
identical names must have identical content).

This will result in a lot of duplicates (objects found in several
packs), but "git gc" should be able to remove them.

(the notice about doing backups before also applies to my
proposal ;-) )

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

Re: How to recovery a corrupted git repo

From: Ping Yin <hidden>
Date: 2016-06-15 22:50:37

On Mon, Feb 21, 2011 at 10:51 PM, Matthieu Moy
[off-list ref] wrote:
Axel Freyn [off-list ref] writes:

There's also the brute-force approach

rsync $good_repo/.git/objects/ $bad_repo/.git/objects/
cd $bad_repo
git gc

Notice the absence of --delete in the rsync command: I'm just adding
new files in the $bad_repo, not deleting any (since files with
identical names must have identical content).
Thanks. This should be an applicable method. However, before rsyncing,
the pack should be unpacked first.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help