55

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?

Chico Sokol
  • 1,254
  • 3
  • 16
  • 24

3 Answers3

73

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
William Seiti Mizuta
  • 7,669
  • 3
  • 31
  • 23
  • 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 Aug 26 '13 at 15:13
  • 7
    thanks, just one thing - the pack files do not need to be inside the repo – Sam Watkins Jan 29 '15 at 12:56
  • I would also add that there's a file `.git/objects/info/packs` which appears to list the pack files available under `.git/objects/packs`. There's also the file `.git/packed-refs` which contains the list of refs (heads, tags) available via pack files. I'm not sure what to do with them after removing the pack files -- may be they need to be removed, may be `git fsck` would take care of them -- I dunno. Just something to keep in mind just in case... – kostix Jul 03 '15 at 16:11
  • 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 Apr 13 '18 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) – Paul Stelian Jul 03 '19 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 Aug 09 '20 at 05:06
  • 1
    This post (`git unpack-objects < SAMPLE/*.pack`) made me do a double-take and think I thought I was mistaken all these years about how Bash handles `<`. **Bash cannot use the `<` operator with multiple files.** You must iterate over them one at a time, e.g. `for fn in SAMPLE/*.pack; do git unpack-objects < "$fn"; done`. – amphetamachine Jan 05 '23 at 15:59
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

0

Maybe you can try a simple command:

git clone ***.git

yingshao xo
  • 244
  • 7
  • 11