Question

I'm using git subtree to split specific package of a java project into another repository (retaining the history) as the following

$ git subtree split -P src/main/java/com/company/package -b moved_package_branch

then when switch to this branch I find that all the content of the package is moved to the root of the project not to it original place (src/main/java/com/company/package)

Any idea about how to fix it?

Was it helpful?

Solution

I have used another git command than subtree as the following

$ git checkout -b moved_package_branch
$ git filter-branch --index-filter 'git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- src/main/java/com/company/package' --prune-empty

Note that you can include multiple folders (space separated)

Reference: last answer from @David Smiley

Detach many subdirectories into a new, separate Git repository

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top