git命令--subtree

[TOC]

subtree 主要命令

git subtree add   --prefix=<prefix> <commit>
git subtree add   --prefix=<prefix> <repository> <ref>
git subtree pull  --prefix=<prefix> <repository> <ref>
git subtree push  --prefix=<prefix> <repository> <ref>
git subtree merge --prefix=<prefix> <commit>
git subtree split --prefix=<prefix> [OPTIONS] [<commit>]

项目地址

https://github.com/test/test_parent.git master
https://github.com/test/test_lib.git master

test_parent 文件结构

.
|--- .git
|--- testfile1
|--- testfile2
|--- sub
|--- subfile1
|--- subfile2
|--- lib
|--- libfile1
|--- libfile2
  • 其中sub文件夹为subtree repo的目录

test_lib 文件结构

.
|--- .git
|--- subfile1
|--- subfile2
|--- lib
|--- libfile1
|--- libfile2

lib repo

lib仓库操作只要正常pull push 就可以 不受影响

parent repo

parent仓库下subtree操作如下

subtree add

parent添加test_lib到parent的sub目录

git subtree add --prefix=sub https://github.com/test/test_lib.git master --squash

(--squash参数表示不拉取历史信息,而只生成一条commit信息。)

subtree pull

parent的sub目录进行代码更新

git subtree pull --prefix=sub https://github.com/test/test_lib.git master --squash

从lib仓库拉取更新后,会在本地仓库自动生成commit信息,此时需要git push origin master , 这样普通parent仓库成员,才能正常拉取已经从lib仓库拉取得更新。

subtree push

git subtree push--prefix=sub https://github.com/test/test_lib.git master --squash

简化命令

使用remote建立子仓库,

git remote add -f lib https://github.com/test/test_lib.git

然后之前得三条subtree命令可以写成这样

git subtree add --prefix=sub lib master --squash
git subtree pull --prefix=sub lib master --squash
git subtree push --prefix=sub lib master

注:建立好子仓库后,简便了操作需要注意自己平时正常得pull操作已经push操作,主要是注意自己得pull和push得remote路径(有些人会直接使用git push或者TortriseGit直接pull或push得习惯),如果在parent直接正常push到lib仓库,一般情况会提醒你存在内容尚未pull下来,然后pull下来之后解决冲突或自动merge,此时如果继续push过去得就会将lib仓库完全替换为parent仓库

提示如下如果出现,请重新审查自己操作是否正确

Pushing to https://github.com/test/test_lib.git
To https://github.com/test/test_lib.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/test/test_lib.git
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

git命令--subtree的更多相关文章

  1. 常look的Git命令

    常用的Git命令   命令  简要说明 git add 添加至暂存区 git add–interactive 交互式添加 git apply   应用补丁 git am  应用邮件格式补丁 git a ...

  2. Git命令详解

    一个中文git手册:http://progit.org/book/zh/ 原文:http://blog.csdn.net/sunboy_2050/article/details/7529841 前面两 ...

  3. Git 命令速查表

    Git 命令速查表 1.常用的Git命令 命令 简要说明 git add 添加至暂存区 git add-interactive 交互式添加 git apply 应用补丁 git am 应用邮件格式补丁 ...

  4. Git命令速查表【转】

    本文转载自:http://www.cnblogs.com/kenshinobiy/p/4543976.html 一. Git 常用命令速查 git branch 查看本地所有分支git status ...

  5. git 命令图解

    git 命令图解   初始化版本库 git config user.name "lsgx" git config user.email "lsgxthink@163.co ...

  6. Git初探--笔记整理和Git命令详解

    几个重要的概念 首先先明确几个概念: WorkPlace : 工作区 Index: 暂存区 Repository: 本地仓库/版本库 Remote: 远程仓库 当在Remote(如Github)上面c ...

  7. 工作中常用的git命令

    一 常用Git命令 git clone:(区分SSH or HTTP) git init:初始化仓库 二 Git命令详解 Git Bash下,cd /c git clone,从远程Git版本库克隆一份 ...

  8. 常用 Git 命令清单

    我每天使用 Git ,但是很多命令记不住. 一般来说,日常使用只要记住下图6个命令,就可以了.但是熟练使用,恐怕要记住60-100个命令. 下面是我整理的常用 Git 命令清单.几个专用名词的译名如下 ...

  9. ***Linux下使用git命令及github项目

    在linux下搭建git环境1.创建Github账号,https://github.com2.Linux创建SSH密钥: ssh-keygen  ##一直默认就可以了 3.将公钥加入到Github账户 ...

随机推荐

  1. sql中的 where 、group by 和 having 用法解析

    --sql中的 where .group by 和 having 用法解析 --如果要用到group by 一般用到的就是“每这个字” 例如说明现在有一个这样的表:每个部门有多少人 就要用到分组的技术 ...

  2. 从0开始学FreeRTOS-(列表&列表项)-6

    # FreeRTOS列表&列表项的源码解读 第一次看列表与列表项的时候,感觉很像是链表,虽然我自己的链表也不太会,但是就是感觉很像. 在FreeRTOS中,列表与列表项使用得非常多,是Free ...

  3. angular4 httpclient拦截器

    1.创建服务: InterceptorService.ts import { Injectable } from '@angular/core'; import { HttpEvent,HttpInt ...

  4. 推荐一款可以丰富博文GIF免费录制工具——GifCam

    在网上写博文,看别人添加gif图片很好奇,于是尝试制作并传递了一次,确实挺有意思的,于是分享一下. gifcam是一个绿色的,可以录制GIF动图的小软件,十分适合用来录制电脑的各种操作. 在这里附上工 ...

  5. GUI tkinter (Entry) 输入框篇

    """1.其他函数不常用,这里只说get函数,get函数使用的时候不需要任何参数,它的返回值就是该输入框的内容.""" from tkint ...

  6. Java12新特性 -- switch表达式

    传统switch表达式的弊端: 匹配是自上而下的,如果忘记写break, 后面的case语句不论匹配与否都会执行: 所有的case语句共用一个块范围,在不同的case语句定义的变量名不能重复: 不能在 ...

  7. 简单自定义mybatis流程!!

    ----简单自定义mybatis流程----一.首先封装daoMapperxml文件和sqlMapconfig配置文件,如何封装:(1).封装我们的Mapper.xml文件,提取名称空间namespa ...

  8. [JOYOI1307] 联络员

    题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 Tyvj已经一岁了,网站也由最初的几个用户增加到了上万个用户,随着Tyvj网站的逐 ...

  9. 在Ubuntu16.0.4安装hipcaffe

    1. 安装 AMD ROCm 显卡条件 要安装AMD的 ROCm显卡,必须满足以下条件,只能高于下面信息版本,不能低于. Distribution Kernel GCC GLIBC x86_64 Fe ...

  10. 下载linux历史版本

    http://blog.csdn.net/u012453843/article/details/52819756