https://lostechies.com/johnteague/2014/04/04/using-git-subtrees-to-split-a-repository/

We are in a position where we needed to create a new back-end后端 server for an application.

The current application is on a MEAN stack (Mongodb, Expressjs, Angularjs, Node.js), but a new client wants the backend to be deployed onto a JBoss server.

This created a situation where we needed a completely different backend, but the front-end was shared between them.

The approach we opted选择 for was using git subtrees to split the ui code into its own repository and shared between the nodejs repo and the Java repo.

We did this by using the subtree features in git.

To be clear, I would only use this for very specific situations like this.

If possible, keeping things simple in a single repository is usually best.

But if you’re in the same situation, hopefully this will be helpful for you.

Splitting the Original Repository

The subtree commands effectively take a folder and split to another repository.

Everything you want in the subtree repo will need to be in the same folder.

For the sake of this example, let’s assume you have a /lib folder that you want to extract to a separate repo.

假设你想把lib文件夹提取成一个独立的版本库

1.Create a new folder and initialize a bare git repo:

首先创建一个新的文件夹,并初始化一个空版本库

mkdir lib-repo
cd lib-repo
git init --bare

2.准备好一个远端版本库,和本地的进行映射

Create a remote repository in github or wherever for lib project and add that as the origin remote.

3.在原项目的文件夹中,执行subtree的命令,将文件夹处理到一个独立的分支split上

From within your parent project folder, use the subtree split command and put the lib folder in a separate branch:

https://github.com/apenwarr/git-subtree/blob/master/git-subtree.txt

prefix:

Specify the path in the repository to the subtree you want to manipulate.
This option is mandatory for all commands.

git subtree split --prefix=lib -b split

4.使用文件路径的方式,将split分支上推送到之第一步创建的版本库上

Push the contents to the of the split branch to your newly created bare repo using the file path to the repository.

git push ~/lib-repo split:master

This will push the split branch to your new repo as the master branch

From lib-repo push to your origin remote

Now that lib folder lives in it’s new repository, you need to remove it from the parent repository and add the subtree back, from it’s new repository:

git remote add lib <url_to_lib_remote>
git rm -r lib
git add -A
git commit -am "removing lib folder"
git subtree add --prefix=lib lib master

还有更多的内容,有兴趣的可以去原文链接看

https://www.cnblogs.com/chucklu/p/4647625.html   用git filter-branch拆分repository

Using Git subtrees to split a repository的更多相关文章

  1. git subtree 拆分split repository

    subtree出现,是为了取代submodule http://wenku.baidu.com/link?url=ola85Z5tIXJpxCjLTk-dcO81ayXLs68_y6dsmXIa0ni ...

  2. git如何merge github forked repository里的代码更新?(转)

    参考内容:git如何merge github forked repository里的代码更新? [refer to ]http://www.haojii.com/2011/08/how-to-git- ...

  3. git如何merge github forked repository里的代码更新

    git如何merge github forked repository里的代码更新? 问题是这样的,github里有个项目ruby-gmail,我需要从fork自同一个项目的另一个repository ...

  4. Git CMD - clone: Clone a repository into a new directory

    命令格式 git clone [--template=<template_directory>]  [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare ...

  5. [Git] Github上传新repository后自动合并

    原因是新repository中有个与老repository一模一样的名字为".git"的隐藏文件夹,删去后即可: 将整个工程直接复制粘贴出此错误...好蠢: Github控制项目的 ...

  6. git如何更新fork的repository(Fork一个别人的repository,做了一些改动,再合并别人的更新)

    Fork一个别人的repository,做了一些改动,想提交pull request的时候,发现原先别人的repository已经又有了一些更新了,这个时候想使得自己fork出的repository也 ...

  7. spring-cloud-config-server——Environment Repository(Git Backend)

    参考资料: https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.0.RELEASE/single/spring-cl ...

  8. 如何在一台主机上管理自己的多个git repository

    在使用git时,通常是直接ssh-keygen生成默认秘钥.然后将共钥添加到远程仓库,就可以访问了. 但是,当我们有多个repository时,这种方式就不适用了,因为一个秘钥只能关联一个远程仓库. ...

  9. 从 Git Gui 管理的Repository(库) 提交更改到 Bonobo服务器管理的Repository(库)

    要提交更改到Bonobo服务器管理的某个Repository(库),必须先得在Bonobo服务器上有此Repository(库)——简直就是废话.那么怎么才能这个Repository(库)变出来呢?其 ...

随机推荐

  1. cf 496B Secret Combination

    题目链接:B. Secret Combination You got a box with a combination lock. The lock has a display showing n d ...

  2. Poj 1029 分类: Translation Mode 2014-04-04 10:18 112人阅读 评论(0) 收藏

    False coin Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16418   Accepted: 4583 Descr ...

  3. HTTP1.1缓存策略

    以下是一幅虽然信息包含量有限.但足够以最简洁的方式说明了“什么是HTTP1.1缓存策略”的图  缓存和缓存策略 web缓存(web cache)或代理缓存(proxy cache)是一种特殊的HTTP ...

  4. Apple Remote Push Notifications

    1.帮助文档参考: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/Remote ...

  5. XSS的原理分析与解剖(一)

    0×01 前言: <xss攻击手法>一开始在互联网上资料并不多(都是现成的代码,没有从基础的开始),直到刺的<白帽子讲WEB安全>和cn4rry的<XSS跨站脚本攻击剖析 ...

  6. 手写PE文件(二)

    [文章标题]: 纯手工编写的PE可执行程序 [文章作者]: Kinney [作者邮箱]: mohen_ng@sina.cn [下载地址]: 自己搜索下载 [使用工具]: C32 [操作平台]: win ...

  7. JAVA float double数据类型保留2位小数点5种方法

    /** * Java 两个整数相除保留两位小数,将小数转化为百分数 * java中,当两个整数相除时,由于小数点以后的数字会被截断,运算结果将为整数,此时若希望得到运算结果为浮点数,必须将两整数其一或 ...

  8. php接收数据

    http://lpladdyy.blog.163.com/blog/static/133999664201010264264585/ PHP默认只识别application/x-www.form-ur ...

  9. UVA 10892 LCM Cardinality 数学

    A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...

  10. hdu 3118(二进制枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边, ...