为什么将现有存储库添加为子模块会修改 .git/config?
如果我添加当前不存在的子模块,则不会将任何子模块信息添加到 .git/config
中。
$ mkdir testing
$ cd testing
$ git init
$ git submodule add [email protected]:submodule.git
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
但是,如果我添加当前作为子模块存在的存储库,则 url 将添加到 .git/config
中:
$ mkdir testing
$ cd testing
$ git init
$ git clone [email protected]:submodule.git
$ git submodule add [email protected]:submodule.git
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[submodule "submodule"]
url = [email protected]:submodule.git
我会假设在这两种情况下,git submodule add
只会修改 .gitmodules
,并且 git submodule init
会更新项目的 .git/config
。
为什么在第二种情况下修改了 .git/config 而不是第一种情况?有人可以解释这种行为的合理性吗?
If I add a submodule that does not currently exist, no submodule information is added to .git/config
.
$ mkdir testing
$ cd testing
$ git init
$ git submodule add [email protected]:submodule.git
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
However, if I add a repo that currently exists as a submodule, the url is added to .git/config
:
$ mkdir testing
$ cd testing
$ git init
$ git clone [email protected]:submodule.git
$ git submodule add [email protected]:submodule.git
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[submodule "submodule"]
url = [email protected]:submodule.git
I would have assumed that in both cases, git submodule add
would have only modified .gitmodules
, and that git submodule init
would have updated the project's .git/config
.
Why is .git/config
modified in the second case but not the first? Can somebody explain the rational for this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来确实很奇怪。 在此提交中引入了该行为:
更新:您已经指出在下面的评论中,我对此提交消息的原始解释没有任何意义,因此我现在删除了该文本以避免其他人感到困惑。
正如下面的评论中提到的,cdwilson 发布到 git 邮件列表来询问这种不一致问题,因此 Jens Lehman 正在致力于修复 - 该线程可以在这里找到:
This does seem strange. That behaviour was introduced in this commit:
Update: you've pointed out in the comments below that my original interpretation of this commit message didn't make any sense, so I've removed that text now to avoid confusion for others.
As mentioned in the comments below, cdwilson posted to the git mailing list to ask about this inconsistency, and as a result Jens Lehman is working on a fix - that thread can be found here:
此问题已在 https://github.com/git/git/commit/2cd9de3e18183422cd7ec3cd81cebc656068ea42
This issue was fixed in https://github.com/git/git/commit/2cd9de3e18183422cd7ec3cd81cebc656068ea42