git从私人仓库下载文件
我想从私人存储库下载文件。我想用“ git”(而不是gitlab/github api)来执行此操作。
git提供这种方式 https://git-scm.com/docs/docs/git-archive 。您可以获取文件喜欢这个,
git archive --remote=ssh://host/pathto/repo.git HEAD README.md
但是我不能使用ssh。我想使用http和一个令牌下载文件。
我可以这样克隆我的回购:
git clone -b branch http://oauth2:$gitToken@${gitRepo}
但是,如果您制作这样的命令:
git archive --remote=http://oauth2:$gitToken@${gitRepo} branch filename
您遇到错误:
fatal: operation not supported by protocol
,问题是我们如何使用令牌从私人git repo下载文件。 (git-archive方法或其他(git)方式)
谢谢
I want to download a file from a private repo. I want to do this with "git" (not gitlab/github api).
Git provide this way https://git-scm.com/docs/git-archive. You can fetch a file like this
git archive --remote=ssh://host/pathto/repo.git HEAD README.md
However I cannot use ssh. I want to download file using http and a token I have.
I can clone my repo like this:
git clone -b branch http://oauth2:$gitToken@${gitRepo}
but if u make a command like this:
git archive --remote=http://oauth2:$gitToken@${gitRepo} branch filename
You encounter an error:
fatal: operation not supported by protocol
So the question is how we can download a file from a private git repo using a token.
(git-archive approach or other (git) way)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GitHub(我怀疑大多数公共git托管服务提供商)不支持通过HTTPS进行远程存档。
更现代的git方式是最近的
git克隆 - 填充
/sparse-checkout
方法另请参见此方法,在其中编辑
.git \ info \ sparse-checkout
GitHub (and I suspect most public Git hosting service provider) does not support remote archiving through HTTPS.
The more modern git way would be the recent
git clone --filter
/sparse-checkout
approachSee also this approach, where I edit
.git\info\sparse-checkout
我已经修改了以前的答案,并有工作脚本仅用于下载一个使用read Access令牌的文件
I have modified previous answer and have got working script for downloading only one file with read access token
我希望对此有一个简单的解决方案。但是,我可以实现下载文件的唯一方法是他们说 。
但是,我修改了仅获取文件的方法,而不是目录,因此它与该指令有所不同。
对于下载文件,您可以做到这一点:
这些git克隆标志是为了最大程度地减少获取额外的文件。
这将在该目录中获取您的文件。
I was hoping there was a straightforward solution to this. But the only way I could achieve downloading files was "sparse-checkout" as they said.
However I modified the way to get only a file, not a directory so it differ from that instruction.
For downloading file u can do this:
Those git clone flags are for minimizing getting extra files.
And this will fetch your file in that directory.