206 git git-checkout sparse-checkout git-sparse-checkout
从远程git存储库获取单个文件内容的最有效机制(关于传输的数据和使用的磁盘空间)是什么?
到目前为止,我已经设法提出:
git clone --no-checkout --depth 1 git@github.com:foo/bar.git && cd bar && git show HEAD:path/to/file.txt
Run Code Online (Sandbox Code Playgroud)
这仍然有点矫枉过正.
如何从回购中获取多个文件?
Yis*_*Dov 136
在git版本1.7.9.5中,这似乎可以从远程导出单个文件
git archive --remote=ssh://host/pathto/repo.git HEAD README.md
Run Code Online (Sandbox Code Playgroud)
这将捕获文件的内容README.md.
Rob*_*ght 59
继Jakub的回答之后. git archive生成tar或zip存档,因此您需要通过tar管道输出以获取文件内容:
git archive --remote=git://git.foo.com/project.git HEAD:path/to/directory filename | tar -x
Run Code Online (Sandbox Code Playgroud)
将从当前目录中的远程存储库的HEAD保存"filename"的副本.
该:path/to/directory部分是可选的.如果排除,则提取的文件将保存到<current working dir>/path/to/directory/filename
此外,如果要启用git archive --remotegit-daemon托管的Git存储库,则需要启用daemon.uploadarch配置选项.请参阅https://kernel.org/pub/software/scm/git/docs/git-daemon.html
Jak*_*ski 42
如果部署了Web界面(如gitweb,cgit,Gitorious,ginatra),您可以使用它来下载单个文件('raw'或'plain'视图).
如果另一方启用了它,您可以使用git archive的' --remote=<URL>'选项(并可能将其限制为给定文件所在的目录),例如:
$ git archive --remote=git@github.com:foo/bar.git --prefix=path/to/ HEAD:path/to/ | tar xvf -
Run Code Online (Sandbox Code Playgroud)
Ank*_*wal 26
不是一般但如果你使用Github:
对于我来说wget,原始网址被证明是下载一个特定文件的最佳和最简单的方法.
在浏览器中打开文件,然后单击"原始"按钮.现在,刷新浏览器,复制该网址并做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
Kou*_*sha 15
要从远程导出单个文件:
git archive --remote=ssh://host/pathto/repo.git HEAD README.md | tar -x
Run Code Online (Sandbox Code Playgroud)
这会将文件下载README.md到您当前的目录.
如果要将文件的内容导出到STDOUT:
git archive --remote=ssh://host/pathto/repo.git HEAD README.md | tar -xO
Run Code Online (Sandbox Code Playgroud)
您可以在命令末尾提供多个路径.
ATo*_*ras 10
如果没有其他答案有效(即限制 GitLab 访问),您可以通过以下方式进行“选择性结帐”:
git clone --no-checkout --depth=1 --no-tags URLgit restore --staged DIR-OR-FILEgit checkout DIR-OR-FILE尽管此解决方案 100% 兼容 git,并且您可以签出目录,但它不像对文件执行 wget/curl 那样在磁盘或网络上都是最佳的。
它看起来像我的解决方案:http://gitready.com/intermediate/2009/02/27/get-a-file-from-a-specific-revision.html
git show HEAD~4:index.html> local_file
其中4意味着从现在起四次修订,并且~是评论中提到的代字号.
我是这样解决的:
git archive --remote=ssh://git@gitlab.com/user/mi-repo.git BranchName /path-to-file/file_name | tar -xO /path-to-file/file_name > /path-to-save-the-file/file_name
Run Code Online (Sandbox Code Playgroud)
如果需要,您可以将“BranchName”替换为“HEAD”
小智 6
我用这个
$ 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'
Run Code Online (Sandbox Code Playgroud)
此处一些答案的细微差别,可以回答OP的问题:
git archive --remote=git@archive-accepting-git-server.com:foo/bar.git \
HEAD path/to/file.txt | tar -xO path/to/file.txt > file.txt
Run Code Online (Sandbox Code Playgroud)
小智 5
在我看来,使用以下内容是最简单的方法:
wget https://github.com/name/folder/file.zip?raw=true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
206747 次 |
| 最近记录: |