1

I am looking to split off a subdirectory in a git repo into a submodule while preserving the (modified) history. (I have tried out subtree but it did not fit my needs regarding the ease of pushing changes.)

My idea for splitting off a subdirectory subproj was as follows:

  1. Create new repo myproj-new
  2. Create new repo subproj
  3. Make a subproj a subrepo of myproj-new
  4. Fetch commits for the original myproj
  5. Rebase these commits onto master of myproj-new

My hope was that git would recognize that subproj is a submodule and would commit any changes to this subdirectory directly there.

Unfortunately this did not automagically work as intended. The result is, that changes to the submodule directory are not committed in the submodule subproj but are still committed in the myproje-new repo.

I was hoping to create a history that looks as if the subdirectory had always been a submodule.

Would the following procedure be correct in principle?

  1. For each changeset in the history, modify the working directory.
  2. Then commit any changes to the submodule,
  3. before committing changes to the parent repo including the new hash of the submodule.

Is there any way to do this in an automated way? (The message of the commits in the submodule should duplicate the messages of the parent repo.)

ARF
  • 7,420
  • 8
  • 45
  • 72
  • [I did something very much like this](https://stackoverflow.com/a/54797306/1290731), is this what you're looking for? – jthill Aug 04 '19 at 07:27
  • @jthill Yes, at first glance, this looks exactly what i was looking for. I just need to study a bit how this works in detail and find a way to do this on windows... Installing a VM for running your handy script seems like overkill. ;-) – ARF Aug 04 '19 at 07:41
  • @jthill Never mind... I just realized that git for windows comes with bash and your script runs fine. Just the result is not quite what I expected. I will comment in your original post. – ARF Aug 04 '19 at 08:40

0 Answers0