Get a single file from a remote git repository

爱⌒轻易说出口 提交于 2019-12-01 17:45:32

git isn't really designed for single file access from a remote repository but you can abuse git archive for this. The downside is that you have to download a "tree" rather than just the blob that you need.

E.g.

git archive --remote=url://to.git.repo branch path/to/dir | tar -x file

As an alternative, if you have gitweb set up on the remote repository you can use a simple curl or wget command to download any file in its "raw" format.

What sort of access to do you have to the remote repository? Is it via SSH, can you call commands? If so, you can just invoke git show HEAD:$path_to_file.

If you cannot invoke commands on that machine, it is still entirely possible to do this, but you'll have to understand the Git repository format. (That’s much less scary than it sounds, since it is very simple by design. Unlike eg. Subversion, the repository format is not intended as a black box.)

Quoth git-clone(1):

--depth depth

Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.

So the granularity is a directory but you can limit the revision history.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!