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. hdu 2883 kebab 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 Almost everyone likes kebabs nowadays (Here a ke ...

  2. poj 1470 Closest Common Ancestors LCA

    题目链接:http://poj.org/problem?id=1470 Write a program that takes as input a rooted tree and a list of ...

  3. C#异常处理策略

    1.如果某些异常,本组件无法处理,不要捕获,但要声明有这个异常.例如SecurityException. 2.如果某些异常,本组件可以处理,捕获并处理它,不再声明此异常.例如DirectoryNotF ...

  4. 关于linux系统如何实现fork的研究(二)

    本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 引言 前一篇关于linux系统如何实现fork的研究(一)通过代码已经说明了从用户态怎么通过软中断实现调用系统调 ...

  5. eclipse sdk 无法更新

    最近祖国越来越强了,强得android开发工具都没法更新了,但是祖国再怎么强也阻挡不了我开发的脚步.下面给大家分享个更新android sdk 的方法.方法原理就是利用国内镜像源. 工具/原料 电脑一 ...

  6. Sqli-labs less 48

    Less-48 本关与less-46的区别在于报错注入不能使用,不进行错误回显,因此其他的方法我们依旧是可以使用的. 可以利用sort=rand(true/false)进行判断. http://127 ...

  7. 使用tomcat7创建异步servlet

    该篇文章翻译自:http://developerlife.com/tutorials/?p=1437 一.简介 Servlet API 3.0 之前,需要使用类似Comet的方式来实现创建异步的Ser ...

  8. codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

    题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...

  9. VMware 11 设置U盘启动,总是找不到physicalDrive1

    问题:VMware 11 设置U盘启动,总是找不到physicalDrive1 先说一下U盘启动的设置:如图 解决方案: 有两个服务没有进行启动,VMware USB Arbitration Serv ...

  10. 李洪强iOS开发之OC面向对象—多态

    OC面向对象—多态 一.基本概念 多态在代码中的体现,即为多种形态,必须要有继承,没有继承就没有多态. 在使用多态是,会进行动态检测,以调用真实的对象方法. 多态在代码中的体现即父类指针指向子类对象. ...