Reputation: 5011
I need to move a subfolder out into a new git repository and then re-add it as submodule to the original repo and preserve original directory structure. Github help suggest to use
git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME
to filter original repo which preserves history related to this folder, etc. However this approach is not complete, good to filter out this dir and its history from original repo and re-add it as submodule at the point in history directory was created.
I have following directory structure:
/
/lib
/mylib
/server
/src
/tests
LICENSE
README.md
Command
git filter-branch --prune-empty --subdirectory-filter lib/mylib master
moves sources to the root of new repo which is not what I want. Same for upper directory:
git filter-branch --prune-empty --subdirectory-filter lib master
keeps mylib
dir in filtered repo (but potentially could grab other libraries - not my case for lucky) and work a little bit better. So what are next steps:
/lib/mylib
and its history from original repo to reduce repo size and improve its structure (simple way just remove it and re-add as submodule)./lib/mylib
repo as submodule to preserve directory structure/lib/mylib
was created to keep repo consistent and sources build-able on any stage (or it has no sense?).Hard to do? Any thoughts?
Upvotes: 1
Views: 262
Reputation: 5011
To keep same paths did the following:
git filter-branch --prune-empty --subdirectory-filter lib master
lib
dir was removed in primary local repo with: git rm -r mylib
git submodule add https://origin_repo/MyLib.git lib
Upvotes: 1