44

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,074
  • 2
  • 15
  • 23

1 Answers1

59

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
  • 7,664
  • 52
  • 54
  • 80
William Seiti Mizuta
  • 6,731
  • 2
  • 28
  • 22
  • 11
    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
  • 5
    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
  • 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
  • @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