57

How can I unpack all objects of a pack file?

I've just cloned a remote repository, so my local repository currently doesn't contain any loose object, only a .pack and a .idx files.

I've tried running git unpack-objects < .git/objects/pack/pack-.pack, but nothing happens.

I'm doing something wrong? Is there any other command to do that?

3 Answers 3

78

You need to move the pack objects outside the .git/objects/pack directory before using the command. However, the pack files need to be inside the repository.

For example, create a directory name SAMPLE in your project's root. Then, move the pack files to SAMPLE directory. After that, inside the repository without the pack files, use the command

git unpack-objects < SAMPLE/*.pack

Git will generate all objects inside .git/objects directory of your repository.

7
  • 13
    Hacky, but valid. The reason this works is that git unpack-objects won't create objects already in the repo, and seeing as the pack file is in the repo it does nothing. This is very clearly explained in get help unpack-objects.
    – Kevin Cox
    Commented Aug 26, 2013 at 15:13
  • 8
    thanks, just one thing - the pack files do not need to be inside the repo Commented Jan 29, 2015 at 12:56
  • 1
    When I try the command git unpack-objects -n < SAMPLE/*.pack, bash gives me an error: bash: SAMPLE/*.pack: ambiguous redirect. Is it because I'm trying to use the -n switch? I wanted to try a dry run before committing to the full unpack...
    – Wilson F
    Commented Apr 13, 2018 at 23:08
  • 1
    @WilsonF You have multiple or no pack files (probably multiple). You need to actually run the command once for every .pack file, and specify its actual filename (you can use tab-completion for that though) Commented Jul 3, 2019 at 17:56
  • 1
    @WilsonF You could also run a simple command like for file in $(ls SAMPLE/); do git unpack-objects < SAMPLE/$file; done and achieve your solution.
    – Jason
    Commented Aug 9, 2020 at 5:06
0

move the *.pack file into .git folder , then go to .git directory and run the following command:

cat YOUR_PACK_FILE.pack | git unpack-objects

1
  • fatal: offset value out of bound for delta base object - from PowerShell
    – Dan
    Commented Jan 25, 2023 at 17:21
-3

Maybe you can try a simple command:

git clone ***.git

Not the answer you're looking for? Browse other questions tagged or ask your own question.