博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git-合并子树
阅读量:4946 次
发布时间:2019-06-11

本文共 2618 字,大约阅读时间需要 8 分钟。

    很多时候 ,"子模块"(submodule)功能不能满足手边的任务。例如,合并多个仓库到一个仓库时,要维护每一个仓库的历史记录。对于这种情况,子树(subtree)合并策略是一个更好的解决方案。

建立仓库,完成第一个合并

在这个例子中,我们建立一个空的“父”仓库,合并别的仓库作为它的子路径。

首先,建立一个空的仓库:

$ mkdir test$ cd test$ git init# Initialized empty Git repository in /Users/tekkub/tmp/test/.git/$ touch .gitignore$ git add .gitignore$ git commit -m "initial commit"# [master (root-commit) 3146c2a] initial commit#  0 files changed, 0 insertions(+), 0 deletions(-)#  create mode 100644 .gitignore

现在,子树合并 到仓库的/cork目录下:

$ git remote add -f cork git://github.com/TekNoLogic/Cork.git# Updating cork# warning: no common commits# remote: Counting objects: 1732, done.# remote: Compressing objects: 100% (750/750), done.# remote: Total 1732 (delta 1086), reused 1558 (delta 967)# Receiving objects: 100% (1732/1732), 528.19 KiB | 621 KiB/s, done.# Resolving deltas: 100% (1086/1086), done.# From git://github.com/tekkub/cork#  * [new branch]      lastbuffed -> cork/lastbuffed#  * [new branch]      lock_n_mount -> cork/lock_n_mount#  * [new branch]      master     -> cork/master#  * [new branch]      nothing_to_see_here -> cork/nothing_to_see_here$ git merge -s ours --no-commit cork/master# Automatic merge went well; stopped before committing as requested

接下来,我们合并到仓库的panda/目录下

$ git remote add -f panda git://github.com/TekNoLogic/Panda.git# Updating panda# warning: no common commits# remote: Counting objects: 974, done.# remote: Compressing objects: 100% (722/722), done.# remote: Total 974 (delta 616), reused 399 (delta 251)# Receiving objects: 100% (974/974), 189.56 KiB, done.# Resolving deltas: 100% (616/616), done.# From git://github.com/tekkub/panda#  * [new branch]      master     -> panda/master#  * [new branch]      transmute  -> panda/transmute$ git merge -s ours --no-commit panda/master# Automatic merge went well; stopped before committing as requested$ git read-tree --prefix=panda/ -u panda/master$ git commit -m "Subtree merged in panda"# [master 726a2cd] Subtree merged in panda

最后,我们将要把tekkub/cork的子目录modules/合并到仓库的cork2/目录结构下。

$ git merge -s ours --no-commit cork/master# Automatic merge went well; stopped before committing as requested$ git read-tree --prefix=cork2/ -u cork/master:modules$ git commit -m "Subtree merged in cork/modules"# [master f240057] Subtree merged in cork/modules

目录结构为

Mode LastWriteTime Length Name

---- ------------- ------ ----
d---- 2013/3/13 12:45 cork
d---- 2013/3/13 12:50 cork2
d---- 2013/3/13 12:48 panda
----- 2013/3/13 12:36 0 .gitignore

 

获取修改

如果将来被合并的仓库中有修改,你只要简单的使用-s subtree标记获取他们的修改。

$ git pull -s subtree panda master

 

原文链接: 

转载于:https://www.cnblogs.com/Mingxx/archive/2013/03/13/2957483.html

你可能感兴趣的文章
Java基础复习1
查看>>
通过目标站点收集信息
查看>>
C#中抽象类和接口的区别
查看>>
materail ui 资源
查看>>
Maven2实践1-环境安装与准备
查看>>
UVA-1611 Crane (构造)
查看>>
linux下的watch命令
查看>>
鼠标滚动兼容
查看>>
WebServer
查看>>
Perl 三种时间time,localtime,gmttime
查看>>
用unity surface shader 重新渲染dota2 模型
查看>>
BZOJ—— 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
查看>>
codevs——T3657 括号序列
查看>>
读书笔记1
查看>>
[spring-boot] 健康状况监控
查看>>
Android 生命周期
查看>>
B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
查看>>
Codeforces Round #540 (Div. 3)题解
查看>>
css选择器,伪类和伪元素的区别
查看>>
Linux系统调优及安全设置
查看>>