git - 是否可以让 Git 知道现有的 .gitmodules 文件?

标签 git git-submodules

我添加了一个子模块:

git submodule add git://github.com/chneukirchen/rack.git rack

文件 .gitmodules 的创建方式如下:

[submodule "rack"]
path = rack
url = git://github.com/chneukirchen/rack.git

当然 Git 知道它:

git submodule status
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)

我手动添加了一个子模块,例如,添加到那个文件:

[submodule "redcloth"]
path = plugins/redcloth
url = git://github.com/jgarber/redcloth.git

然后我重复了之前的命令:

git submodule init
Submodule 'rack' () registered for path 'rack'

git submodule update
(no output)

git submodule status
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)

因此,据我所知,我手动添加的内容被忽略了。有没有办法让 Git 知道在 .gitmodules 文件中手动添加的行?

注意:我也尝试过手动将这些行添加到 .git/config 文件中,但这也没有用。

最佳答案

好吧,多亏了 Adam,我找到了答案,虽然很明显,但还是在这里:

如果您检查 git submodule add 做了什么,您会注意到它做了三件事:

  1. 将行添加到 .gitmodules 文件,
  2. 在您在命令中确定的“路径”中克隆存储库,并且
  3. 将模块添加到 .git/config 文件。

因此,基本上,手动添加子模块的 repo 与通过 git submodule 命令添加的 repo 之间的唯一区别是 repo 本身的内容。

用同样的例子回答,你应该:

$ git clone git://github.com/jgarber/redcloth.git plugins/redcloth

将以下内容添加到 .git/config 文件*:

[submodule "redcloth"]
url = git://github.com/jgarber/redcloth.git

确保至少将它们添加到 git 存储库中:

$ git add plugins/redcloth

然后检查 git 是否真的“知道”:

$ git submodule status
0766810ab46f1ed12817c48746e867775609bde8 plugins/redcloth (v4.2.8)
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)

*请注意,您在 .gitmodules 文件中使用的“路径”变量在该文件中并不需要

关于git - 是否可以让 Git 知道现有的 .gitmodules 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7629822/

相关文章:

git - 如何自动更新git hooks?

git - 如何通过父项目中的 .gitattributes 强制子模块中的行结尾为 LF?

git - Jenkins 和更新 git 子模块

Git 子模块添加 : "a git directory is found locally" issue

git - 如何获取 `git clone --recursive` 以重新创建子模块的 Remote 和分支?

git - 与多个用户一起使用 Git SVN 和远程 Git 存储库的工作流程

git - 将 Jupyter 与文件共享或挂载文件夹一起使用

git:子模块跟踪当前分支

gitignore 仍然包含 dll 文件

windows - GIT 日志或提交监视器