简体   繁体   English

在保留和缩小分支范围的同时拆分git存储库

[英]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. 关于如何将大型git存储库(LargeRepo)拆分为较小的存储库(SmallRepoA,SmallRepoB)并保存提交的大量教程。 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 . 我想通过附加要求做到这一点,即每个SmallRepo仅继承那些与SmallRepo中的文件相关的分支和分支提交

For each SmallRepo: 对于每个SmallRepo:

  1. Don't maintain a branch if the branch has no affect on the files in SmallRepo 如果分支对SmallRepo中的文件没有影响,请不要维护分支
  2. For the remaining branches, remove commits that have no affect on the files in SmallRepo. 对于其余分支,删除对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. 有效地,我试图获得最终结果,以模仿如果我有一个单独的SmallRepos开始时世界的样子。

Here's an example: 这是一个例子:

Lets say LargeRepo looks like this: 可以说LargeRepo看起来像这样:

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

And I want to split into three SmallRepos, one for each high-level Folder. 我想分为三个SmallRepos,每个高级文件夹一个。

Folder1
Folder2
Folder3

Lets say LargeRepo had Branch1 and Branch23. 假设LargeRepo具有Branch1和Branch23。 Branch1 made changes to files in Folder1, Branch23 made changes to files in Folder2 and Folder3. Branch1更改了Folder1中的文件,Branch23更改了Folder2和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. 理想情况下,该解决方案可以在Windows上使用git命令行实现,并且不涉及BASH。

This general solution for splitting a repo also works for de-scoping branches: https://stackoverflow.com/a/17864475/356790 这种用于拆分存储库的常规解决方案也适用于对分支进行范围界定: 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. 出于某种原因,它不适用于我在本地创建的存储库,但对于我从GitHub克隆的存储库来说效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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