与其他用户一起更新 git 子模块
我在我的机器上以用户 A 身份登录,但可以通过我从中提取数据的服务器上的用户名 B 访问我的存储库。 .gitmodules
文件具有 url = ssh://domain.com/abc/def.git
。
当我执行 git submodule update 时,如何配置 git 使用用户名 B 而不是 A?
I'm logged in as user A on my machine, but my repo is accessible through username B on the server that I pull from. The .gitmodules
file has url = ssh://domain.com/abc/def.git
.
How can I configure git to use a username B instead of A when I do git submodule update
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设子模块已经初始化,所以 git config --list | grep ^submodule 显示类似
submodule.my-submodule.url=ssh://domain.com/abc/def.git
的内容。如果您还没有第一次运行 git submodule update ,那么您可以更改该配置选项,例如:
另一方面,如果子模块已经更新过一次,则 <子模块中的 code>origin 将被设置为指定的配置选项。在这种情况下,您需要这样做:
恐怕这有点令人困惑,但子模块非常灵活。我尝试在一篇博客文章中解释其中一些细节。
I assume that the submodule has already been initialized, so
git config --list | grep ^submodule
shows something likesubmodule.my-submodule.url=ssh://domain.com/abc/def.git
.If you haven't yet run
git submodule update
for the first time, then you can just change that config option, e.g. with:On the other hand, if the submodule has already been updated once, then
origin
in the submodule will have been set to whatever that config option specified. In that case, you'll need to do:It's just a bit confusing, I'm afraid, but submodules are very flexible. I made an attempt to explain some of these details in a blog post.
虽然上述解决方案有效,但我找到了更适合我的需求(也许是原始请求者的需求)的不同解决方案。我想要一种方法来为远程服务器上的所有 git 操作指定默认用户名,而不必修改每个项目的 git 配置。该解决方案实际上与 git 根本没有任何关系,而是 ssh。
只需将这些行添加到您的 ~/.ssh/config 中:(
将 domain.com 替换为您的 git 服务器的域。)现在,即使您以用户 A 身份登录到本地计算机,SSH 也会使用 B 作为用户名连接到服务器时。
现在您可以运行 git submodule update ,而无需在 git 配置中添加用户名。
While the above solution works, I found a different solution that better suits my needs, and maybe the original requester's. I wanted a way to specify the default username for all git operations on a remote server instead of having to modify the git configs for each project. The solution doesn't really have anything to do with git at all, but ssh.
Simply add these lines to your ~/.ssh/config:
(replace domain.com with the domain of your git server.) Now, even if you are logged in to your local machine as user A, SSH will use B as the username when connecting to the server.
Now you can run
git submodule update
without having to add a username in the git config.简短的答案是“检查是否可以使用子模块的相对路径”
详细信息是,
我们有多个应用程序正在使用的子模块。我们已将子模块保留在同一个存储库中。
结构是这样的,
当我们克隆应用程序
时,app/.git/config 会获取当前用户的 url,例如 '[电子邮件受保护]'
在应用程序的 .gitmodules 中,我们将 url 指定为“../submod”
这样,当我们执行“submodule init”时,git 会根据我们在 .gitmodules 中给出的相对 url 生成子模块的绝对 url。
The short answer is 'check if you could use relative paths for submodules'
The detail is,
We have submodule that is being used by multiple apps. We have kept the submodule in the same repo.
The structure is like this,
repo
When we clone the app the app/.git/config gets url with current user like '[email protected]'
In the .gitmodules of apps we give url as '../submod'
By this way, when we do 'submodule init', git generates absolute url for submodule from the relative url we gave in .gitmodules.