From: Linus Torvalds <torvalds@linux-foundation.org>
To: Alexander Litvinov <litvinov2004@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: My git repo is broken, how to fix it ?
Date: Tue, 27 Feb 2007 20:57:28 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0702272039540.12485@woody.linux-foundation.org> (raw)
In-Reply-To: <200702281036.30539.litvinov2004@gmail.com>
On Wed, 28 Feb 2007, Alexander Litvinov wrote:
>
> Some times ago I descide to run fsck and found that by working repo is broken,
> while imported repo is correct. Is there way to fix it ?
Generally, the best way to fix things is (I've written this up at
somewhat more length before, but I'm too lazy to find it):
- back up all your state so that anything you do is re-doable if you
corrupt things more!
- explode any corrupt pack-files
See "man git-unpack-objects", and in particular the "-r" flag. Also,
please realize that it only unpacks objects that aren't already
available, so you need to move the pack-file away from its normal
location first (otherwise git-unpack-objects will find all objects
that are in the pack-file in the pack-file itself, and not unpack
anything at all)
- replace any broken and/or missing objects
This is the challenging part. Sometimes (hopefully often!) you can find
the missing objects in other copies of the repositories. At other
times, you may need to try to find the data some other way (for
example, maybe your checked-out copy contains the file content that
when hashed will be the missing object?).
- make sure everything is happy with "git-fsck --full"
- repack everything to get back to an efficient state again.
And remember: git does _not_ make backups pointless. It hopefully makes
backups *easy* (since cloning and pulling is easy), but the basic need for
backups does not go away!
> By the way, several times I interrupt git's commands like commit and pull
> using Ctrl-C.
Shouldn't matter, at least as long as you are using the native git
protocol: git will create objects fully under a temporary name, and then
atomically rename things to their right names.
Using rsync and/or http may not be as safe.
HOWEVER! I do not know how well Windows and/or cygwin does file renames.
If cygwin does a rename as a copy + delete, a lot of the safety
assumptions just fly out the window.
> I tried to unpack all objects:
>
> > git-unpack-objects -r < .git/objects/pack/pack-c4554978bbe079c9a43d6a13546a2fa314fe0884.pack; echo $?
> Unpacking 12868 objects
> 100% (12868/12868) done
Ok, that's a good thing, but see above: I don't think anything should have
gotten unpacked, because it found all objects already existing in the very
pack-file you tried to unpack.
So you might well need to do
mv .git/objects/pack/pack-c4554978bbe079c9a43d6a13546a2fa314fe0884.pack oldpack
git-unpack-objects -r < oldpack
(or rename the .idx file instead).
Alternatively (and in many ways this migth be better when you're trying to
recover something) just create a totally *new* git repo, by doing
mkdir new-repo
cd new-repo
git init
git unpack-objects -r < ../other-repo/.git/pack/pack-.....pack
and re-create the objects somewhere else - you can do all of this without
at all disturbing the old repository (but you'd need to copy all the refs
and all the loose objects by hand, of course!)
> No erorts here. But fsck find that broken blob:
> > git fsck
> dangling blob beb992198d4d8813ea51fd1cbbf38313ef490c22
>
> git-cat-file shows me this this is a broken object with correct sha1 sum.
>
> As a cunclusion: my repo has broken file and I don't see there is the brakage.
> Can I reconstruct file by sha1 sum :-) or can I do something to stop fsck
> warn me ?
You didn't do "--full", so it's not looking inside your pack, so the fsck
wasn't very interesting in this case.
And no, you cannot reconstruct the file by sha1 sum, although you may be
able to reconstruct the file some *other* way (by looking at the other
blobs and remembering what the missing case is), and then you can
obviously use the sha1-sum to *confirm* that you reconstructed the file
exactly as it was!
So yes, reconstruction of missing objects is possible, but no, you can't
do it based purely based on SHA1, you need to base reconstruction on some
other information. That's kind of what "cryptographically secure hash"
means ;^p
Linus
next prev parent reply other threads:[~2007-02-28 4:57 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-28 4:36 My git repo is broken, how to fix it ? Alexander Litvinov
2007-02-28 4:57 ` Linus Torvalds [this message]
2007-02-28 11:54 ` Alexander Litvinov
2007-02-28 16:19 ` Linus Torvalds
2007-02-28 19:12 ` Alex Riesen
2007-03-19 13:32 ` Alexander Litvinov
2007-03-19 15:20 ` Linus Torvalds
[not found] ` <200703201013.39169.litvinov2004@gmail.com>
2007-03-20 5:34 ` Linus Torvalds
2007-03-20 6:55 ` Alexander Litvinov
2007-03-20 7:42 ` Junio C Hamano
2007-03-20 15:23 ` Nicolas Pitre
[not found] ` <Pine.LNX.4.64.0703200832150.6730@woody.linux-foundation.org>
[not found] ` <Pine.LNX.4.64.0703200836490.6730@woody.linux-foundation.org>
[not found] ` <200703210956.50018.litvinov2004@gmail.com>
2007-03-22 15:58 ` Linus Torvalds
2007-03-22 16:34 ` Nicolas Pitre
[not found] ` <200703211024.04740.litvinov2004@gmail.com>
2007-03-22 16:17 ` Linus Torvalds
2007-03-22 16:29 ` Linus Torvalds
2007-03-22 16:48 ` Linus Torvalds
2007-03-22 17:01 ` Nicolas Pitre
2007-03-22 17:10 ` Linus Torvalds
2007-03-22 17:28 ` Nicolas Pitre
2007-03-22 22:13 ` Jeff King
2007-03-23 0:25 ` Linus Torvalds
2007-03-23 0:42 ` Bill Lear
2007-03-23 0:51 ` Jeff King
2007-03-22 20:31 ` [PATCH] git-apply: Do not free the wrong buffer when we convert the data for writeout Junio C Hamano
2007-03-22 20:55 ` Linus Torvalds
2007-03-23 3:55 ` Alexander Litvinov
2007-03-23 3:40 ` My git repo is broken, how to fix it ? Alexander Litvinov
2007-03-22 17:12 ` Johannes Sixt
-- strict thread matches above, loose matches on Subject: below --
2021-06-06 17:27 B
2021-06-06 17:28 B
2021-12-25 8:30 Joseph Mitchell
2021-12-26 0:48 ` Lemuria
2023-05-29 18:57 ross thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0702272039540.12485@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=litvinov2004@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).