git 如何从 GitHub 下载 .zip 以获取特定提交 sha?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13636559/
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
How to download .zip from GitHub for a particular commit sha?
提问by ChocoDeveloper
I want to download a .zip with the source of a library hosted on github, but I don't want the master, because every time I download I could be downloading a different version.
我想下载一个带有托管在 github 上的库源的 .zip,但我不想要 master,因为每次下载时我都可能下载不同的版本。
This particular library does not have tags, so I can't use that.
这个特定的库没有标签,所以我不能使用它。
So how do I download the source.zip for a specific commit sha?
那么如何下载特定提交 sha 的 source.zip 呢?
回答by Zeki
You can put the sha that you want in the download url:
你可以把你想要的 sha 放在下载 url 中:
https://github.com/{username}/{projectname}/archive/{sha}.zip
https://github.com/{username}/{projectname}/archive/{sha}.zip
As a general rule, if you have a url that works, you can replace "master" with the specific sha you want.
作为一般规则,如果你有一个有效的 url,你可以用你想要的特定 sha 替换“master”。
On unix:
在Unix上:
wget https://github.com/{username}/{projectname}/archive/{sha}.zip
wget https://github.com/{username}/{projectname}/archive/{sha}.zip
Keep in mind that if this is a private repo then wget will not work unless you pass an OAuth token as well.
请记住,如果这是一个私有存储库,那么 wget 将无法工作,除非您也传递 OAuth 令牌。
Here's more info on that:
这里有更多信息:
Having trouble downloading Git archive tarballs from Private Repo
回答by user2722591
When viewing the commit's code, click the button "Browse Code" on the upper right, after that click on "Download ZIP".
查看提交的代码时,单击右上角的“浏览代码”按钮,然后单击“下载 ZIP”。
回答by trojanfoe
This is a an old question, but wanted to mention that if you want just the commit as a patch, and not the whole repo at the time of the commit, you can use:
这是一个老问题,但想提一下,如果您只想要提交作为补丁,而不是提交时的整个存储库,您可以使用:
$ wget http://github.com/username/repo/commit/sha1.patch
# ^^^^^^^^ ^^^^ ^^^^
# change change change
The /commit
and .patch
parts being the important part.
在/commit
与.patch
部分作为重要的组成部分。
This is particularly useful if you want to merge in a change that was reversed a while back and therefore doesn't exist in the forked repo.
如果您想合并一段时间前撤消的更改,因此它不存在于分叉存储库中,这将特别有用。