从GitHub repo下载单个文件有哪些技巧?
我不想要显示原始文件的URL;对于二进制文件,什么都没有。
http://support.github.com/discussions/feature-requests/41-download-single-file
是否有可能将GitHub用作“下载服务器”?
如果我们决定切换到GoogleCode,是否提供了上述功能?
或者开源项目是否有免费托管和VCS?
从GitHub repo下载单个文件有哪些技巧?
我不想要显示原始文件的URL;对于二进制文件,什么都没有。
http://support.github.com/discussions/feature-requests/41-download-single-file
是否有可能将GitHub用作“下载服务器”?
如果我们决定切换到GoogleCode,是否提供了上述功能?
或者开源项目是否有免费托管和VCS?
当前回答
您可以使用V3API获取如下原始文件(需要OAuth令牌):
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept:
application/vnd.github.v3.raw' -O -L
https://api.github.com/repos/*owner*/*repo*/contents/*path*
所有这些都必须在一条线上进行。-O选项将文件保存在当前目录中。可以使用-o filename指定其他文件名。
要获取OAuth令牌,请遵循以下说明。
我也把这个写下来作为要点。
其他回答
可以这样使用curl:
卷曲-OLhttps://raw.githubusercontent.com/<username>/<repo名称>/<branch名称>/path/to/file
O表示curl下载内容L表示卷曲遵循重定向
只需将wget与raw=True参数一起使用
wget "https://github.com/user/repository/blob/master/directory/file_name?raw=True" -O target_path/file_name
为了跟进thomasfuchs所说的,但对于GitHub Enterprise用户,您可以使用以下内容。
curl-H'授权:令牌INSERTACCESSTOKENHERE'-H'接受:application/vnd.github.v3.raw'-O-Lhttps://your_domain/api/v3/repos/owner/repo/contents/path
这里还有API文档https://developer.github.com/v3/repos/contents
请使用“{host}/{user}/}repo}/branch}/{file}”的模式。要获得具体示例,请在Python中执行以下操作:
import pandas as pd
host = 'raw.github.com'
user = 'fivethirtyeight'
repo = 'data'
branch = 'master'
file = 'births/US_births_2000-2014_SSA.csv'
url = f'https://{host}/{user}/{repo}/{branch}/{file}'
df = pd.read_csv(url,sep=',',header=0)
df.head()
您链接到的页面回答了第一个问题。GitHub还提供了一个下载工具,用于发布等内容。谷歌代码根本没有Git。GitHub、Google Code和SourceForge是免费托管。SourceForge可能仍然会做CVS。