转自  https://stackoverflow.com/questions/2428137/how-to-rebase-one-git-repository-onto-another-one

If A and B are not the same repo (you created B by using the latest working copy you had), you have to use a graft to pretend that they have common history.

Let’s assume you’ve added A as a remote for B as per VonC’s answer, and the repo looks like this1:

~/B$ git tnylog
* (HEAD, master) Latest work on B
* 799d6ae Imported backup from USB stick
~/B$ git tnylog A/master
* 33b5b16 (A/master) Head of A
* Initial commit

Create a graft telling the root of B that its parent is the head of A:

echo '799d6aeb41095a8469d0a12167de8b45db02459c 33b5b16dde3af6f5592c2ca6a1a51d2e97357060' \
>> .git/info/grafts

Now the two histories above will appear as one when you request the history for B. Making the graft permanent is a simple git filter-branch with no arguments. After the filter-branch, though, you aren’t on any branch, so you should git branch -D master; git checkout -b master.


1 git tnylog = git log --oneline --graph --decorate

补充句话:Git太厉害了!!!

Git merge two repositories (ZZ)的更多相关文章

  1. 聊下git merge --squash

    你经常会面临着将dev分支或者很多零散的分支merge到一个公共release分支里. 但是有一种情况是需要你处理的,就是在你的dev的分支里有很多commit记录.而这些commit是无需在rele ...

  2. 分支合并git checkout adview git merge adview3

    分支合并 git checkout adview git merge adview3

  3. [git]merge和rebase的区别

    前言 我从用git就一直用rebase,但是新的公司需要用merge命令,我不是很明白,所以查了一些资料,总结了下面的内容,如果有什么不妥的地方,还望指正,我一定虚心学习. merge和rebase ...

  4. git merge 和 git rebase 小结

    Git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 ---------------------- ...

  5. Git merge 与 git rebase的区别

    Git merge的用法: git merge Dev // Dev表示某分支,表示在当前分支合并Dev分支 git merge -m  "Merge from Dev"  Dev ...

  6. git merge 和 rebase 区别

    git pull  超级不推荐使用git pull 有坑,谨慎使用,pull底层是merge git pull 是 git fetch + git merge FETCH_HEAD 的缩写.所以,默认 ...

  7. git merge之squash

    看CM源码时,发现历史记录里有很多squash,于是google了解了一下. Git相对于CVS和SVN的一大好处就是merge非常方便,只要指出branch的名字就好了,如: 1 2 3 4 5 $ ...

  8. git merge 合并分支

    git merge 用来做分支合并,将其他分支中的内容合并到当前分支中.比如分支结构如下: master / C0 ---- C1 ---- C2 ---- C4 \ C3 ---- C5 \ iss ...

  9. git merge

    1. git 解决冲突 ***** <<<<<<< HEAD *** *** ======= **** **** ** >>>>> ...

随机推荐

  1. CSS box-flex属性,然后弹性盒子模型简介(转)

    一.淡淡的开头语 昨天趁着不想工作的时间间隙闲逛24ways,在My CSS Wish List一文中,见到了个新鲜的CSS属性,就是题目中的box-flex,以前没有见过,顿生疑惑,不知是骡子还是马 ...

  2. 【译】PHP中的Session及其一些安全措施

    有一点我们必须承认,大多数web应用程序都离不开session的使用.这篇文章将会结合php以及http协议来分析如何建立一个安全的会话管理机制.我们先简单的了解一些http的知识,从而理解该协议的无 ...

  3. [Linux] ubuntu 格式化u盘

    $sudo fdisks -l 基本功,格式化命令,以格式化 /dev/sdb4 分区为例:$ sudo umount /dev/sdb4    # 必须先卸载该分区 # 格式化为 FAT 分区$ s ...

  4. verynginx +nginx_upstream_check_module模块,负载均衡检查模块。

    yum -y install git yum -y install patch yum -y install pcre-devel yum install -y zlib-devel   mkdir ...

  5. 【转载】【Todo】Nodejs的优缺点

    Nodejs的优缺点,这里面讲的比较详细.有时间可以多看看别人的分析. https://www.zhihu.com/question/19653241 Node.js 的架构与 Django, Rai ...

  6. 使用Nmon监控Linux的系统性能

    Nmon(得名于 Nigel 的监控器)是IBM的员工 Nigel Griffiths 为 AIX 和 Linux 系统开发的一款计算机性能系统监控工具.Nmon 可以把操作系统的统计数据展示在屏幕上 ...

  7. 常见配置Server错误导致import 包无效等问题解决

  8. 深入NIO Socket实现机制(转)

    http://www.jianshu.com/p/0d497fe5484a# 前言 Java NIO 由以下几个核心部分组成: Buffer Channel Selector 以前基于net包进行so ...

  9. ActiveMQ Spring 集成配置

    <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms&l ...

  10. 常见的七大排序算法Java实现

    /** * @author Javen * @Email javenlife@126.com * 2015年12月9日 */ public class Sorting { static int[] a ...