git从私人仓库下载文件

发布于 2025-01-22 06:01:44 字数 826 浏览 6 评论 0原文

我想从私人存储库下载文件。我想用“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓬勃野心 2025-01-29 06:01:44

GitHub(我怀疑大多数公共git托管服务提供商)不支持通过HTTPS进行远程存档。

更现代的git方式是最近的git克隆 - 填充/sparse-checkout方法

git clone --filter=blob:none --sparse https://[token]@github.com/CSSEGISandData/COVID-19.git
cd COVID-19/
git sparse-checkout init --cone
git sparse-checkout add /the folder you want/

另请参见此方法,在其中编辑.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 approach

git clone --filter=blob:none --sparse https://[token]@github.com/CSSEGISandData/COVID-19.git
cd COVID-19/
git sparse-checkout init --cone
git sparse-checkout add /the folder you want/

See also this approach, where I edit .git\info\sparse-checkout

冷︶言冷语的世界 2025-01-29 06:01:44

我已经修改了以前的答案,并有工作脚本仅用于下载一个使用read Access令牌的文件

 git clone --depth 1 --filter=blob:none \
  -b master https://<my_token_name>:<my_token>@<my_git_repo>.git tmp_dir && \
  cd tmp_dir && \
  git sparse-checkout set <path_to_file_in_repo> && \
  git checkout master && \
  test -f <path_to_file_in_repo>

I have modified previous answer and have got working script for downloading only one file with read access token

 git clone --depth 1 --filter=blob:none \
  -b master https://<my_token_name>:<my_token>@<my_git_repo>.git tmp_dir && \
  cd tmp_dir && \
  git sparse-checkout set <path_to_file_in_repo> && \
  git checkout master && \
  test -f <path_to_file_in_repo>
一枫情书 2025-01-29 06:01:44

我希望对此有一个简单的解决方案。但是,我可以实现下载文件的唯一方法是他们说

但是,我修改了仅获取文件的方法,而不是目录,因此它与该指令有所不同。

对于下载文件,您可以做到这一点:

git clone --depth 1 --filter=blob:none --no-checkout -b branchName http://oauth2:$gitToken@$gitRepo repoFolder
cd repoFolder
git sparse-checkout set $fileName

这些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:

git clone --depth 1 --filter=blob:none --no-checkout -b branchName http://oauth2:$gitToken@$gitRepo repoFolder
cd repoFolder
git sparse-checkout set $fileName

Those git clone flags are for minimizing getting extra files.

And this will fetch your file in that directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文