如何稀疏地从git存储库中仅签出一个文件? [英] How to sparsely checkout only one single file from a git repository?

查看:86
本文介绍了如何稀疏地从git存储库中仅签出一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从git存储库中仅检出一个文件?

How do I checkout just one file from a git repo?

推荐答案

最初,我在2012年提到过 git archive (请参见 Jared Forsyth answer 罗伯特·奈特答案),因为 Paul Brannan answer :

Originally, I mentioned in 2012 git archive (see Jared Forsyth's answer and Robert Knight's answer), since git1.7.9.5 (March 2012), Paul Brannan's answer:

git archive --format=tar --remote=origin HEAD:path/to/directory -- filename | tar -O -xf -

但是:在2013年,对于远程https://github.com URL ,不再可能.
> 参见旧页面"

But: in 2013, that was no longer possible for remote https://github.com URLs.
See the old page "Can I archive a repository?"

当前(2018年)页面"关于存档GitHub上的内容和数据"建议使用第三方服务,例如 GHTorrent

The current (2018) page "About archiving content and data on GitHub" recommends using third-party services like GHTorrent or GH Archive.

因此,您还可以处理本地副本/克隆:

So you can also deal with local copies/clone:

如果您具有此答案

git --no-pager --git-dir /path/to/bar/repo.git show branch:path/to/file >file


或者您必须先克隆该存储库,这意味着您可以获得完整的历史记录: -在.git仓库中 -在工作树中.


Or you must clone first the repo, meaning you get the full history: - in the .git repo - in the working tree.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆