Alan Harper
Alan Harper

Reputation: 803

Git restore pack index file

I have a git repo with *.pack files - no loose objects. For some reason ,not related to the question, all *.idx files are lost. How can I restore them?

thanks

Upvotes: 6

Views: 4105

Answers (2)

VonC
VonC

Reputation: 1324557

Note: "git index-pack --stdin" needs an access to an existing repository, but "git index-pack file.pack" to generate an .idx file that corresponds to a packfile does not.

That means, from Git 2.12 (Q1 2017) on, you can even restore an idx file from outside a Git repo, for testing purpose.

See commit 29401e1, commit a3c45d1, commit 7176a31, commit de95302 (16 Dec 2016) by Jeff King (peff). (Merged by Junio C Hamano -- gitster -- in commit 49d45de, 21 Dec 2016)

index-pack: skip collision check when not in repository

You can run "git index-pack path/to/foo.pack" outside of a repository to generate an index file, or just to verify the contents.
There's no point in doing a collision check, since we obviously do not have any objects to collide with.

Upvotes: 1

John Szakmeister
John Szakmeister

Reputation: 47032

From the top of your tree, try running:

git index-pack .git/objects/pack/PACK_FILENAME

where PACK_FILENAME is the name of your pack file. For instance, a repository I tried this on had the path:

.git/objects/pack/pack-7e0af787b3e455fac722264ff05dd0bae7d71625.pack

You should do that for each pack file, and you're repository should be in working order again.

Upvotes: 9

Related Questions