How do I download a specific git commit from a repository?

前端 未结 8 2345
北海茫月
北海茫月 2020-12-15 06:10

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.o

8条回答
  •  北海茫月
    2020-12-15 06:29

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

    $ git archive -o repo.tar --remote= 
    

    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=;a=snapshot;h=;sf=tgz. So for your repo, you could use, say, wget or curl to grab the file using that URL.

提交回复
热议问题