2

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 ...

  • ... should be committable from the main without having to commit and push from the sub project
  • ... should still be committable from the sub project

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:

  • Deleted .gitsubmodule
  • Deleted the submodule sections from .git/config
  • rm --cached my_subprojects
  • git add/commit/push

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)
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
  • Did you follow the 7 steps from this answer http://stackoverflow.com/a/1260982/880584 to delete your submodule? – Patrick B. Aug 04 '14 at 12:43
  • Well, I did not do the step 5 because I didn't have any `.git/modules` directory and neither the step 7 because I don't want to delete the files (but rather include them into the main repository) – Pierre de LESPINAY Aug 04 '14 at 12:49

2 Answers2

2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
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.

simpleigh
  • 2,854
  • 18
  • 19
  • I indeed care about committing in the sub projects. I guess you are talking about [subtrees](http://git-scm.com/book/en/Git-Tools-Subtree-Merging). That actually sounds to be what I'm searching for. I'll try that. – Pierre de LESPINAY Aug 04 '14 at 13:22