Pierre de LESPINAY
Pierre de LESPINAY

Reputation: 46158

git - Including submodules into the main repository

It's been about 6 months I used submodules for subprojects developed alongside a main project with a dev team.

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

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

For several reasons now I'd like to consider my sub projects as regular files in the main repository.
So modifications in one of the sub projects ...

The question is How to disable these submodules ?
I mean disable and not delete, as I need the files in the main repository


Here is what I did:

Now when I try to merge this, the subprojects seem still considered as submodules as I still see

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

Upvotes: 2

Views: 98

Answers (2)

VonC
VonC

Reputation: 1323303

You still need to remove the gitlink (special entry in the index which marks the folder as a submodule, and records the SHA1 for that submodule)

git rm --cached my_subprojects # no trailing /

The only other command is the git submodule deinit my_subprojects which takes care of the .gitmodules, .git/modules and git/config.

Then you can add my_subprojects repo as a subtree.

Upvotes: 2

simpleigh
simpleigh

Reputation: 2894

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.

Upvotes: 1

Related Questions