与其他用户一起更新 git 子模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6041516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git submodule update with other user
提问by Jonas Bystr?m
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
.
我在我的机器上以用户 A 的身份登录,但我的存储库可以通过我拉取的服务器上的用户名 B 访问。该.gitmodules
文件具有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
?
当我这样做时,如何配置 git 以使用用户名 B 而不是 A git submodule update
?
回答by Mark Longair
I assume that the submodule has already been initialized, so git config --list | grep ^submodule
shows something like submodule.my-submodule.url=ssh://domain.com/abc/def.git
.
我假设子模块已经初始化,所以git config --list | grep ^submodule
显示类似submodule.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:
如果您还没有git submodule update
第一次运行,那么您可以更改该配置选项,例如:
git config submodule.my-submodule.url ssh://[email protected]/abc/def.git
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:
另一方面,如果子模块已经更新过一次,那么origin
子模块中将被设置为指定的任何配置选项。在这种情况下,您需要执行以下操作:
cd my-submodule
git config remote.origin.url ssh://[email protected]/abc/def.git
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.
恐怕这有点令人困惑,但是子模块非常灵活。我试图在博客文章中解释其中的一些细节。
回答by Steve Rank
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.
虽然上述解决方案有效,但我找到了一个更适合我的需求的不同解决方案,也许是原始请求者的需求。我想要一种方法来为远程服务器上的所有 git 操作指定默认用户名,而不必修改每个项目的 git 配置。该解决方案与 git 根本没有任何关系,而是与 ssh 无关。
Simply add these lines to your ~/.ssh/config:
只需将这些行添加到您的 ~/.ssh/config 中:
Host domain.com
User B
(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.
(将 domain.com 替换为您的 git 服务器的域。)现在,即使您以用户 A 的身份登录到本地计算机,SSH 连接到服务器时也会使用 B 作为用户名。
Now you can run git submodule update
without having to add a username in the git config.
现在您git submodule update
无需在 git 配置中添加用户名即可运行。
回答by siliconsenthil
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.
详细信息是,我们有多个应用程序正在使用的子模块。我们将子模块保存在同一个 repo 中。
The structure is like this, repo
结构是这样的,repo
|-app1 |-app2 |-submod
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.
当我们克隆应用程序时,app/.git/config 获取当前用户的 url,如“[email protected]” init', git 根据我们在 .gitmodules 中给出的相对 url 生成子模块的绝对 url。