My requirement: Break down one git repo, into multiple git repos, preserving the same directory structure as in the original repo, and preserve the commit history for the files that are copied to the new repo. What I have tried already:
First I tried git filter-branch --subdirectory-filter based on the suggestions in http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/ Result: The history is maintained, but can be viewed only on running git log --follow Also, the original commit history cannot be seen on Github. It just displays my merge commit as the only commit for that file, and does not display any previous commits. I can still live with this limitation and accept it as a solution. But another concern I have with this approach is that, for each folder and each file that I want to copy, I need to clone the original repo multiple times and also repeat all those 12 or 13 steps everytime. I would like to know if there is any simpler way of doing it, since I'm moving a lot of files around. Also, since the post is 5 years old, just wondering if newer easier solutions are available? (Surprisingly Google mostly shows this blog as the first search result)
Next thing I tried was a comment on the earlier Greg Bayer's post http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/#comment-2685894846 This solution made things a bit simpler by using git subtree split but the results were same as listed in the first case.
Then I tried the git log --patch-with-stat and git am option based on this answer https://stackoverflow.com/a/11426261/5497551 Result: This usually gives errors on encountering a merge, while applying the patch. I tried one of the suggestions to this answer of using -m --first-parent This resolved the errors but does not expand any merges into their commits, just lists the merge as a single commit. Hence most of the commit history is lost. So I added another option of --3way. This went over and over through the commits, and did not lead to any acceptable solution.
In conclusion, I would prefer using the 3rd solution, if only there was an option to have all the commits in a merge to be listed in the history of the new repo. Else I have to stick to the first solution which is a bit inconvenient and tedious in my situation. Any advice, help would be greatly appreciated.
Thanks.