2

大约 6 个月以来,我将子模块用于与开发团队一起与主项目一起开发的子项目。

- v-- Repository (developer(s)) --v

- Main project (dev team)
    - Sub project 1 (me)
    - Sub project 2 (me)

由于几个原因,现在我想将我的子项目视为主存储库中的常规文件。
因此,在其中一个子项目中进行修改...

  • ...应该可以从主项目提交,而不必从子项目提交和推送
  • ...应该仍然可以从子项目中提交

问题是如何禁用这些子模块
我的意思是禁用而不是删除,因为我需要主存储库中的文件


这是我所做的:

  • 已删除.gitsubmodule
  • 删除了子模块部分.git/config
  • rm --cached my_subprojects
  • git add/commit/push

现在,当我尝试合并它时,子项目似乎仍然被视为子模块,因为我仍然看到

modified:   Sub project 1 (new commits)
modified:   Sub project 2 (new commits)
4

2 回答 2

2

您仍然需要删除gitlink (索引中的特殊条目将文件夹标记为子模块,并记录该子模块的 SHA1)

git rm --cached my_subprojects # no trailing /

唯一的其他命令是git submodule deinit my_subprojects处理.gitmodules,.git/modulesgit/config

然后您可以my_subprojectsrepo 添加为子树

于 2014-08-04T14:54:41.080 回答
1

If you want to keep the existing files then don't forget to also remove the .git file from each submodule's path.

A submodule is defined in the following places:

  • .gitmodules (not .gitsubmodules as you state above)
  • .git/modules (the actual repository)
  • path/to/module/.git (placeholder pointing to commit ID)
  • git/config

If you've cleaned these all up then you should be fine, but make sure that branching / merging isn't biting you - .gitmodules and path/to/module/.git are under version control so may differ on different branches.

There's another issue with what you're trying to do that you may or may not care about - you won't preserve any of the commit history of your submodules. You can preserve the commit history by adding each submodule as a remote and then merging in appropriate remote branches.

于 2014-08-04T13:01:01.827 回答