简体   繁体   中英

Split git repository while preserving and scoping-down branches

There are numerous tutorials on how to split a large git repository (LargeRepo) into smaller repositories (SmallRepoA, SmallRepoB) and preserve commits. I'd like to do that with the added requirement that each SmallRepo inherits only those branches and branch commits that are relevant to the files in the SmallRepo .

For each SmallRepo:

  1. Don't maintain a branch if the branch has no affect on the files in SmallRepo
  2. For the remaining branches, remove commits that have no affect on the files in SmallRepo.

Effectively, I'm trying to get the end result to micmic what the world would look like if I had the individual SmallRepos to begin with.

Here's an example:

Lets say LargeRepo looks like this:

LargeRepo
|---- Folder1
|---- Folder2
|---- Folder3

And I want to split into three SmallRepos, one for each high-level Folder.

Folder1
Folder2
Folder3

Lets say LargeRepo had Branch1 and Branch23. Branch1 made changes to files in Folder1, Branch23 made changes to files in Folder2 and Folder3.

The branch view would look like this:

Folder1
|----> Branch1 (all commits)

Folder2
|-----> Branch23 (only commits affecting files in Folder2)

Folder3
|------> Branch23 (only commits affecting files in Folder3)

Ideally the solution can be implemented with the git command-line on Windows and would not involve BASH.

This general solution for splitting a repo also works for de-scoping branches: https://stackoverflow.com/a/17864475/356790

For some reason it didn't work with a repo I created locally, but worked fine for a repo I cloned from GitHub.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM