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. Java 查询URL对应IP地址

    /** * @ClassName TestSocket1 * @Version 1.0 * @Date 2014-9-26 上午10:19:36 */ public class TestSocket1 ...

  2. ios UI实现技巧

    statusBar 移动位置 NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned ] enco ...

  3. 使用JFinal-weixin配置微信开发

    先扯点闲话,申请好公众号后,一直因为没有域名.没有外网IP而没有尝试过开发微信服务.后来发现nat123可以从内网直接映射到外网,但是nat123需要钱或者T币大于0,于是为了赚一个T币,签到灌水了一 ...

  4. 我的第一款windows phone软件

    我的第一个windows phone应用发布成功了,大家支持下,名字叫吕氏春秋,发布人是我的英文名xmfdsh http://www.windowsphone.com/zh-cn/store/app/ ...

  5. WPF 与Surface 2.0 SDK 亲密接触 - ScatterView 数据绑定篇

    与我们常用的一些WPF 控件相同,ScatterView 控件也支持数据绑定功能.本篇将演示如何利用ScatterView 绑定Win7 系统中的样例图片,并且每张图片会以独立的ScatterView ...

  6. codeforces #240 div 2

    A:语文题,估计大家都会, B题:假如答案是ans,求最大的ans,是w*a/b==(w-ans)*a/b; 明显的二分,可是我的二分写的没水准,还有是直接做: #include<string. ...

  7. 提高Asp.Net应用程序性能的十大方法(译感)

    译完了提高Asp.Net应用程序的十大方法这篇文章,仔细想其中提到的每一条,在这里结合我的项目来谈谈.第一条:返回多个结果集因为我的项目中所有对数据库的访问的sql语句都是通过调用存储过程实现的,所以 ...

  8. 火狐和IE之间的7个JavaScript差异

    尽管 JavaScript 历史上使用冗长而令人生厌的代码块来标的特定浏览器的时期已经结束了,但是偶尔使用一些简单的代码块和对象检测来确保一些代码在用户机器上正常工作依然是必要的. 这篇文章中,我会略 ...

  9. POJ 1236

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10500   Accepted: 41 ...

  10. php 如何判断一个常量是否已经定义

    php 如何判断一个常量是否已经定义 http://blog.csdn.net/raojinpg/article/details/6222882 如果看过手册的人肯定知道,可以直接忽视 不过在实际项目 ...