8

In an answer to a question about the internal format of git’s tree objects, to get to one particular tree object that was stored in a pack, I unpacked all of the objects in a repository’s packfiles using git unpack-objects. That seems like overkill. Yes, I realize that commands such git show --raw, git ls-tree, or git cat-file will get close to the internal format.

How do I make git output a single object in its internal format — complete with blob, tree, commit, or tag header — regardless of whether it is stored in loose or packed format?

Community
  • 1
  • 1
Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
  • 2
    You can just zlib decompress it with `zpipe -d < ` from within `.git/objects` – Andrew C Mar 10 '16 at 04:30
  • @AndrewC Yes, if it’s already a loose object, but what if it lives in a pack? – Greg Bacon Mar 10 '16 at 05:06
  • Greg I thought the premise of your question was that you had unpacked the objects and had a loose object. I don't know the answer to doing it from a pack file except to unpack it first. – Andrew C Mar 10 '16 at 05:12

1 Answers1

7

You can use git pack-objects first to make a pack with only this one object.

Note also that git unpack-objects does not extract objects which already exist in a repository, so you probably want to make a new repository. Overall something like this should work:

$ DIR=$(mktemp -d)
$ echo 5e98806c6cc246acef5f539ae191710a0c06ad3f \
   | git pack-objects --stdout \
   | ( cd "$DIR" && git init && git unpack-objects )

Then look for your unpacked object in $DIR/.git/objects

max630
  • 8,762
  • 3
  • 30
  • 55