从远程git存储库获取单个文件内容的最有效机制(就传输的数据和使用的磁盘空间而言)是什么?

到目前为止,我已经想出了:

git clone --no-checkout --depth 1 git@github.com:foo/bar.git && cd bar && git show HEAD:path/to/file.txt

这似乎还是有些过分。

从回购中获取多个文件呢?


当前回答

下面两个命令对我来说很有用:

Git存档——remote={remote_repo_git_url} {branch} {file_to_download} -o {tar_out_file}

从远程存储库的分支(url为remote_repo_git_url)下载file_to_download作为tar归档文件,并存储在tar_out_file中

Tar -x -f {tar_out_file}.tar从tar_out_file中提取file_to_download文件

其他回答

对于单个文件,只需使用wget命令。

首先,按照下面的图片点击“raw”来获取url,否则你将下载嵌入html中的代码。

然后,浏览器将打开一个新页面,url以https://raw.githubusercontent.com/开头…

只需在终端输入命令:

#wget https://raw.githubusercontent.com/...

一会儿文件就会放在你的文件夹里。

一般来说不是,但如果你使用Github:

对我来说,wget到原始url是下载一个特定文件的最佳和最简单的方法。

在浏览器中打开文件,点击“Raw”按钮。现在刷新浏览器,复制url并对其执行wget或curl操作。

wget的例子:

wget 'https://github.abc.abc.com/raw/abc/folder1/master/folder2/myfile.py?token=DDDDnkl92Kw8829jhXXoxBaVJIYW-h7zks5Vy9I-wA%3D%3D' -O myfile.py

旋度的例子:

curl 'https://example.com/raw.txt' > savedFile.txt

我用这个

$ cat ~/.wgetrc
check_certificate = off

$ wget https://raw.github.com/jquery/jquery/master/grunt.js
HTTP request sent, awaiting response... 200 OK
Length: 11339 (11K) [text/plain]
Saving to: `grunt.js'

在我看来,使用以下方法是最简单的:

wget https://github.com/name/folder/file.zip?raw=true

直接从浏览器(我使用safari…)右键单击“查看原始”,选择“下载链接文件”: