git 如何从 GitHub 下载 ZIP 格式的源代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2751227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:20:18  来源:igfitidea点击:

How to download source in ZIP format from GitHub?

gitgithub

提问by dontWatchMyProfile

I see something strange like:

我看到一些奇怪的东西:

http://github.com/zoul/Finch.git

http://github.com/zoul/Finch.git

Now I'm not that CVS, SVN, etc. dude. When I open that in the browser it tells me that I did something wrong. So I bet I need some hacker-style tool? Some client?

现在我不是那个 CVS、SVN 等等。当我在浏览器中打开它时,它告诉我我做错了什么。所以我打赌我需要一些黑客风格的工具?某个客户?

(I mean... why not just provide a ZIP file? Isn't the world complex enough?)

(我的意思是......为什么不只提供一个 ZIP 文件?这个世界还不够复杂吗?)

采纳答案by Kurt

To clone that repository via a URLlike that: yes, you do need a client, and that client is Git. That will let you make changes, your own branches, merge back in sync with other developers, maintain your own source that you can easily keep up to date without downloading the whole thing each time and writing over your own changes etc. A ZIP file won't let you do that.

要通过这样的URL克隆该存储库:是的,您确实需要一个客户端,该客户端是Git。这将使您能够进行更改、您自己的分支、与其他开发人员同步合并、维护您自己的源代码,您可以轻松地保持最新状态,而无需每次都下载整个内容并覆盖您自己的更改等。一个 ZIP 文件获胜不让你那样做。

It is mostly meant for people who want to develop the source rather than people who just want to get the source one off and not make changes.

它主要适用于想要开发源代码的人,而不是只想获取源代码而不进行更改的人。

But it just so happens you can get a ZIP file as well:

但碰巧你也可以得到一个 ZIP 文件:

Click on http://github.com/zoul/Finch/and then click on the green Clone or Downloadbutton. See here:

单击http://github.com/zoul/Finch/,然后单击绿色Clone or Download按钮。看这里:

enter image description here

在此处输入图片说明

回答by user892731

What happens when the repository owner has not prepared a zip file, and you just want a download to use yourself? There is an answer and you don't need to go though that horrid process to download software, install and register keys and whatnot on GitHub, etc.!

当存储库所有者没有准备 zip 文件而您只想下载以供自己使用时会发生什么?有一个答案,你不需要通过那个可怕的过程来下载软件、安装和注册密钥等等!

To simply download a repository as a zip file: add the extra path '/zipball/master/' to the end of the repository URL and voila, it gives you a zip file of the whole lot.

要简单地将存储库下载为 zip 文件:将额外的路径“/zipball/master/”添加到存储库 URL 的末尾,瞧,它为您提供了整个 zip 文件。

For example,

例如,

http://github.com/zoul/Finch/

http://github.com/zoul/Finch/

becomes:

变成:

http://github.com/zoul/Finch/zipball/master/

http://github.com/zoul/Finch/zipball/master/

It then gives you a zip file to download.

然后它会为您提供一个 zip 文件供您下载。

回答by Manav Kataria

Updated July 2016

2016 年 7 月更新

As of July 2016, the Download ZIPbutton has moved under Clone or download to extreme-rightof header under the Codetab:

截至2016年7月,在Download ZIP按钮下方移动Clone or download 极右的标题下方的Code标签:

Download ZIP (2013)

下载 ZIP (2013)



If you don't see the button:

如果您没有看到按钮:

  • Make sure you've selected <> Codetab from right side navigation menu, or
  • Repo may not have a zip prepared. Add /archive/master.zipto the end of the repository URL and to generate a zipfile of the master branch:
  • 确保您<> Code已从右侧导航菜单中选择选项卡,或
  • Repo 可能没有准备好 zip。添加/archive/master.zip到存储库 URL 的末尾并生成 master 分支的 zipfile:

http://github.com/user/repository/-to-> http://github.com/user/repository/archive/master.zip

http://github.com/user/repository/-到-> http://github.com/user/repository/archive/master.zip

to get the master branch source code in a zip file. You can do the same with tags and branch names, by replacing masterin the URL above with the name of the branch or tag.

获取 zip 文件中的 master 分支源代码。您可以对标签和分支名称执行相同的操作,方法是将master上面的 URL替换为分支或标签的名称。

回答by Willy

To download your repository as zip file via curl:

要通过以下方式将存储库下载为 zip 文件curl

curl -L -o master.zip http://github.com/zoul/Finch/zipball/master/

If your repository is private:

如果您的存储库是私有的:

curl -u 'username' -L -o master.zip http://github.com/zoul/Finch/zipball/master/

Source: Github Help

来源:Github 帮助

回答by Bendy

As of December 2016, the Clone or downloadbutton is still under the <> Codetab, however it is now to the far right of the header:

截至 2016 年 12 月,该Clone or download按钮仍位于<> Code选项卡下,但现在位于标题的最右侧:

Github Clone or download screenshot

Github 克隆或下载截图

回答by Paul Baumer

Here's a good reference if you want to do it from the command line: http://linuxprograms.wordpress.com/2010/10/26/checkout-code-from-github/

如果您想从命令行执行此操作,这是一个很好的参考:http: //linuxprograms.wordpress.com/2010/10/26/checkout-code-from-github/

Basically it's

基本上是

git clone http://github.com/zoul/Finch.git

回答by Raja Anbazhagan

Even though this is fairly an old question, I have my 2 cents to share.

尽管这是一个相当古老的问题,但我有 2 美分要分享。

You can download the repo as tar.gz as well

您也可以将 repo 下载为 tar.gz

Like the zipballlink pointed by various answers here, There is a tarballlink as well which downloads the content of the git repository in tar.gzformat.

就像zipball这里各种答案指向的链接一样,还有一个tarball链接以格式下载 git 存储库的内容tar.gz

curl -L http://github.com/zoul/Finch/tarball/master/

A better way

更好的方法

Git also provides a different URL pattern where you can simply append the type of file you want to download at the end of url. This way is better if you want to process these urls in a batch or bash script.

Git 还提供了不同的 URL 模式,您可以在其中简单地在 url 末尾附加要下载的文件类型。如果您想在批处理或 bash 脚本中处理这些 url,这种方式会更好。

curl -L http://github.com/zoul/Finch/archive/master.zip

curl -L http://github.com/zoul/Finch/archive/master.tar.gz

To download a specific commit or branch

下载特定的提交或分支

Replace masterwith the commit-hashor the branch-namein the above urls like below.

替换为上面网址中mastercommit-hash或 ,branch-name如下所示。

curl -L http://github.com/zoul/Finch/archive/cfeb671ac55f6b1aba6ed28b9bc9b246e0e.zip    
curl -L http://github.com/zoul/Finch/archive/cfeb671ac55f6b1aba6ed28b9bc9b246e0e.tar.gz

curl -L http://github.com/zoul/Finch/archive/your-branch-name.zip
curl -L http://github.com/zoul/Finch/archive/your-branch-name.tar.gz

回答by clamum

I've been stumped by this too. The "Download" button is to the far right, but you also need to be in the top folder in order to download what you're seeing. Go up as high as you can to the parent/root folder and then look for the download button.

我也被这个难住了。“下载”按钮位于最右侧,但您还需要位于顶部文件夹中才能下载您所看到的内容。尽可能上到父/根文件夹,然后查找下载按钮。

回答by Rohan Gadad

Sometimes if the 'Download ZIP' button is not available, you can click on 'Raw' and the file should download to your system.

有时,如果“下载 ZIP”按钮不可用,您可以单击“原始”,文件就会下载到您的系统中。

回答by Reginaldo Camargo Ribeiro

As of June 2016, the Download ZIP button is still under the <> Code tab, however it is now inside a button with two options clone or download:

截至 2016 年 6 月,下载 ZIP 按钮仍位于 <> 代码选项卡下,但它现在位于具有两个选项克隆或下载的按钮内:

Symfony image example

Symfony 图像示例