我可以添加用户名和名称吗?使用 --recursive 选项(对于子模块)的 git clone 密码?

发布于 2024-10-26 07:01:29 字数 1216 浏览 0 评论 0 原文

我正在使用 git 通过 https 克隆存储库:

git clone https://username:password@alocation/git/repo.git

这很好,但它也有大量的子存储库可供克隆,因此我使用 --recursive 选项。

这里的问题是,对于顶层来说,它需要用户名和名称。通过指定,但对于每个子存储库,它再次要求提供详细信息,因此我得到以下信息:

C:>git clone --recursive https://username:password@alocation/git/repo.git
Cloning into repo...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 15 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
Submodule 'sub1' (https://alocation/git/repo.sub1) registered for path 'sub1'
Submodule 'sub2' (https://alocation/git/repo.sub2) registered for path 'sub2'
Submodule 'sub3' (https://alocation/git/repo.sub3) registered for path 'sub3'
Submodule 'sub4' (https://alocation/git/repo.sub4) registered for path 'sub4'
Cloning into sub1...
Username:
Password:
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 10 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
Username:
..............................etc....

我可以提供用户名和密码吗?密码分开,这样我就不必每次都输入。

明显的用例是像这样有大量文件的深层子存储库结构。为每个子存储库输入相同的数据将会变得乏味且繁琐。容易出错。

I am using git to clone a repo via https thus:

git clone https://username:password@alocation/git/repo.git

This is fine but it has a large number of subrepos to clone as well so I am using the --recursive option.

Problem here is that for the top level it takes the username & pass specified but for each sub repo it asks for the details again so I get the following:

C:>git clone --recursive https://username:password@alocation/git/repo.git
Cloning into repo...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 15 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
Submodule 'sub1' (https://alocation/git/repo.sub1) registered for path 'sub1'
Submodule 'sub2' (https://alocation/git/repo.sub2) registered for path 'sub2'
Submodule 'sub3' (https://alocation/git/repo.sub3) registered for path 'sub3'
Submodule 'sub4' (https://alocation/git/repo.sub4) registered for path 'sub4'
Cloning into sub1...
Username:
Password:
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 10 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
Username:
..............................etc....

Can I give the username & password separably so I don't have to enter each time.

Obvious use case is for a deep subrepo structure like this where there are lots of files. Entering the same data for each subrepo is going to get tedious & error prone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

聚集的泪 2024-11-02 07:01:29

凭据对于任何具有接受它们的地址的子模块都应该有效。

唯一可能失败的情况是 .gitmodules 文件指向另一个存储库,如 Hunch Kod 项目的案例 214

为了确保这些凭据传递到“分配”服务器的每个请求,您不需要在 Git 中调整任何内容,但这可能是 ssh、curl 或 http 代理设置。

我会排除 ssh (分配不会以“用户名”执行任何操作,而是希望有一个专用的用户帐户)。

如果您有代理,请检查您的 http_proxy 和 https_proxy 环境变量。

但也可以尝试一个简单的curl https://alocation/git/repo.git
使用 $HOME/.netrc(Windows 上为 %HOME%\_netrc),您可以指定所需的登录名/密码。

machine alocation
  login username
  password mypassowrd

如果这适用于 https://alocation/git/repo.git (即不要求您提供用户名和密码),它也适用于任何其他存储库(此处为子模块)。

The credentials should be valid for any submodules with an address supposed to accept them.

One only case where it could fail is when the .gitmodules file points to another repo, as illustrated by the case 214 of the Hunch Kod project.

To make sure those credentials are passed to every request to 'alocation' server, you don't need to tweak anything in Git, but this is probably a ssh, curl or http proxy settings.

I would rule out ssh (alocation wouldn't execute anything as 'username' but would rather have a dedicated user account).

Check your http_proxy and https_proxy environment variable if you have a proxy.

But try also a simple curl https://alocation/git/repo.git:
With a $HOME/.netrc (%HOME%\_netrc on Windows), you can specify the login/password expected.

machine alocation
  login username
  password mypassowrd

If that work for https://alocation/git/repo.git (i.e. without asking you for a username and password), it will work for any other repo( here submodules).

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