ocharles
ocharles

Reputation: 6070

How can I split a repository apart into smaller atomic repositories?

I've read "Detach subdirectory into separate Git repository" but I'm not quite sure how to use this to achieve what I'm looking for. We currently have one large project that contains our schema/entities, our front-end web processes, and 2 versions of our REST API. I'd love to separate all of this into separate repositories if possible. Here's the kind of directory structure we have at the moment:

lib/Project/Entity/*.pm
lib/Projcet/Data/*.pm
lib/Project/Server/Controller/*.pm
lib/Project/Server/Controller/WS/1/*.pm
lib/Project/Server/Controller/WS/2/*.pm
lib/Project/Server/Form/*.pm

And so on. I'd like to be able to take the Entity and Data directories and move them to a new repository, and preferably move them as well:

lib/Project/Schema/Entity/*.pm
lib/Project/Schema/Data/*.pm

With the remaining files I'd like to split them apart into 2 more repositories, one for our front end server, and one for the REST API. I figure even though the REST API has 2 different versions we can split this into 2 separate branches (v1 and v2 branches).

I feel like filter-branch is pretty much exactly what I want (maybe with additional commits on top to move files), but I can't quite see exactly how to make this happen. Does anyone have any advice?

I should add that maybe git rm --ignore-unmatch might be what I want, but the file structure in HEAD at the moment is most certainly not what the structure was in older commits (this repository spans almost a decade of history). What I really want is "take commits that touch these files: foo but ignore all other commits. Sort of like a UNION of git log :)

Upvotes: 2

Views: 289

Answers (1)

Wes Hardaker
Wes Hardaker

Reputation: 22262

The git command you're looking for can be found in git filter-branch. It is able to take an existing git tree and include only certain components from it. Note that it rewrites your git tree. So make sure you have a backup of the tree or copy it into a different directory and operate in the new directory.

For stuff in a subdirectory, note this part of the manual which describes how to do it well:

   To rewrite the repository to look as if foodir/ had been its project
   root, and discard all other history:

       git filter-branch --subdirectory-filter foodir -- --all

Upvotes: 2

Related Questions