Reputation: 88578
I'm doing some advanced usage of Git, querying objects in order to make optimizations of test runs of my code, so bear with me if the following sounds very far from the usage that most people do with Git.
I want to do something like git cat-file -p [...]
, except on objects on a remote, without fetching them. i.e., I want to say, "On remote origin
, show me commit A
, specifically tell me what's the id of its tree; then show me the contents of the tree (list of blobs and subtrees.)" I don't need to fetch actual contents of files, just the information above.
I know I could just fetch the commit from the remote to my local repo and use git cat-file
on it, but then it'll involve fetching all the parents of the commit from the remote, which can take a long time. I need this to be quick because it's done in a program that should run hundreds of times a day on many different repositories.
Is there a way to do the above without fetching the commit?
Upvotes: 6
Views: 432
Reputation: 8345
I assume that you already verified that git fetch --depth=...
does not do what you want.
If you have ssh/scp
access to remote, you can simply grab the indiviudal file for that commit (if the commit as the hash a1b2c3d4
, it is stored inside the file objects/a1/b2c3d4
). Place it in your local .git/objects
under the same directory/name. Then use the local git cat-file
as usual. From its output, you can parse the hash of the tree, and go on from there, fetching individual object files until done. git cat-file
does not care about any missing bits, if you have a hash for which the file exists, it will happily output its content.
To avoid problems in your "real" local repository, you can do this in an empty repos, i.e. one you just created with git init tmprepos
or whatever. It does not hurt that there is nothing else in there.
EDIT: git stores some objects inside pack files. See https://git-scm.com/book/en/v1/Git-Internals-Transfer-Protocols for instructions how to get at them.
Upvotes: 1