如何解压一个git对象? [英] How do I unpack a single git object?
问题描述
在回答有关git树形对象内部格式的问题中,获取一个特定的树形对象存储在一个包中,我使用 git unpack-objects
。这似乎是矫枉过正。是的,我意识到命令如 git show --raw
, git ls-tree
或 git cat-file
会将内部格式的关闭。
如何让git输出一个单一的对象的内部格式 - 完整的 blob
,树
, commit
或标记
标题 - 无论它是以宽松还是打包格式存储?
您可以使用 git包 - 对象首先制作一个只包含这一个对象的包。
还要注意,git unpack-objects不会提取存储库中已经存在的对象,所以你可能想创建一个新的存储库。总的来说,像这样的应该是这样的:
$ $ $ code $ $ $ $ $(mktemp -d)
$ echo 5e98806c6cc246acef5f539ae191710a0c06ad3f \
| git pack-objects --stdout \
| (cd$ DIR&&&git init&&& git unpack-objects)
然后在 $ DIR / .git / objects
中查找您的解包对象
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?
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
这篇关于如何解压一个git对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!