tags:

views:

236

answers:

5

I don't have a local code copy/etc, I just want to download a single specific git commit so I can view it. I have the url for the git repository:

git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.git

and the commit hash:

ee9c5cfad29c8a13199962614b9b16f1c4137ac9

How can I download just this commit using git (I don't want the whole repo, just the one commit patch)? I have read the man pages for git-pull and git-cherry-pick and fiddled with the commands with no luck.

Cloning the repo really isn't an option because some of the Kernel repositories are exceedingly large and slow to download (hours).

A: 
git show COMMITID

But you have to clone the repo. No way around that, I think. But you can do a shallow clone using the --depth arg.

Also, found a good SO post that covers this topic in greater depth http://stackoverflow.com/questions/1178389/browse-and-display-files-in-a-git-repo-without-cloning

Joshua Smith
+4  A: 

In the general case, you can do this using the --remote flag to git archive, like so:

$ git archive -o repo.tar --remote=<repo url> <commit id>

So in your example, you'd use:

$ git archive -o repo.tar --remote=git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.git ee9c5cfad29c8a13199962614b9b16f1c4137ac9

That'll give you the state of the repo at that point in time. Note that you won't get the whole repo, so you can't actually interact with the upstream repo with what you've downloaded.

However, using git archive remotely has to be enabled server-side, and it isn't on the Linux kernel's Git server. You can, however, grab a copy by using a URL of the form http://git.kernel.org/?p=&lt;path to repo>;a=snapshot;h=<commit id>;sf=tgz. So for your repo, you could use, say, wget or curl to grab the file using that URL.

mipadi
Unfortunately this method isn't reliable/scriptable (and some git repos don't have easily found web interfaces if at all).
bigredbob
True, but in your specific case, it would work.
mipadi
It should work, except that the web stuff is generated on the fly. The results of `curl http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=snapshot;h=ee9c5cfad29c8a13199962614b9b16f1c4137ac9;sf=tgz` are `<body>Generating...</body>`
Will
@Will: You'll have to handle that response in a script or whatnot, or just paste the link into a browser. It is obtuse, but Git doesn't provide a simple way to grab just one commit.
mipadi
Fair enough. "Obtuse" is absolutely the right word.
Will
+9  A: 

This would appear to be impossible. According to a discussion on kernel.org, the protocol will only allow named refs to be fetched. If you don't wish to download the snapshot from the git website, you'll have to clone the entire repo.

(You may wish to read the manuals for git-fetch and git-ls-remote.)

jleedev
+1  A: 

From mipadi's suggestion, using the "snapshot" option. Copy this into a browser:

http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=snapshot;h=ee9c5cfad29c8a13199962614b9b16f1c4137ac9;sf=tgz

The download's about 85 megs.

Edit: If you do end up using this method, I think it goes without saying that you should credit mipadi with the answer. I was just spelling it out.

Will
So what you actually wanted to do, was writing a comment to mipadis solution? ;)
erikb
Clearly, I was trying too hard. You can lead a horse to water ...
Will
A: 

In this case, if all you want is the diff, you can download it from the web frontend for the kernel repo at this url: http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commitdiff_plain;h=ee9c5cfad29c8a13199962614b9b16f1c4137ac9

You can play with the url to get other commits.

Daenyth