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:
- Create new repo
myproj-new
- Create new repo
subproj
- Make a
subproj
a subrepo ofmyproj-new
- Fetch commits for the original
myproj
- 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?
- For each changeset in the history, modify the working directory.
- Then commit any changes to the submodule,
- 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.)