1

Following advice in Convert a git folder to a submodule retrospectively? I have prepared an online repository and I am ready to start testing by removing the old folder and replacing it with the submodule - see switching a subdirectory managed by git to a submodule.

But everywhere I looked people first commit the folder removal and then the addition of the submodule (random example1, example2).
This however results in a broken commit on master (as the files in the subfolder are of course needed) and this is a nono.

So is there some reason people add the submodule in a separate commit ?
Is there some reason submodules updates should be in a separate commit in general ?

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361

1 Answers1

2

So is there some reason people add the submodule in a separate commit ? Is there some reason submodules updates should be in a separate commit in general ?

Adding submodule means adding/modifiying a .gitmodules file and a gitlink (the special entry in the index recording the SHA1 of the submodule)

You don't have to make a commit recording the deletion and then one recording the new submodule: you could try and do both within the same index, resulting on one commit.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks ! I know what a submodule addition entails - but in general you can think of no reason that submodules modifications should be in a separate commit ? Like it would mess up later removal of the submodule (just saying, I don't know, it's just one of the things one has to get right on first try) – Mr_and_Mrs_D Jul 01 '16 at 12:05
  • @Mr_and_Mrs_D Generally, each commit reflect one simple action. Deletion and addition tend to be in their own commit. But here you can group them in their own commit. – VonC Jul 01 '16 at 12:46
  • Thanks - I was just wondering if there is some reason people do this. Commits reflect a simple action but an iron rule is that commits on the stable branch should not break the build, so the commit we remove the subfolder would result in recording in the master branch a broken state - yak ! So, in this case, _I have_ to commit removal and submodule addition together. – Mr_and_Mrs_D Jul 01 '16 at 13:04
  • @Mr_and_Mrs_D I agree. That seems the correct way to transition to a submodule here. – VonC Jul 01 '16 at 13:06