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. @DateTimeFormat注解

    @DateTimeFormat在spring-context依赖下,所在包如下 当form表单中出现时间字段需要跟pojo对象中的成员变量进行数据绑定时,springmvc框架中的时间数据无法自动绑定 ...

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

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

  3. POJ 3616Milking Time

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

  4. 洛谷P1613 跑路

    题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零.可是小A偏偏又有赖床的坏毛病.于是为了保住自己的工资,小A买了一个十分牛B的空间跑路器,每秒钟 ...

  5. GUI tkinter (pack、grid、place)布局篇

    """1.其实我们已经接触过 tkinter 的一种布局,就是 pack 布 局,它非常简单,我们不用做过多的设置,直接使用一个 pack 函数就可以了.2.grid 布 ...

  6. Io流的概述

    Io流的概述IO: I输入(Input),O 输出(Output)1.什么是IO流? 数据流,IO是严格的“水流模型” 所以IO流是用来读写数据,或者传输数据. 注意:File只能操作文件对象本身,而 ...

  7. django创建表单以及表单数据类型和属性

    08.15自我总结 关于django的表单不同关系之间的创建 一.不同关系之间的创建 1.一对一 举例 母表:userinfo id name age 1 张三 12 2 李四 58 字表:priva ...

  8. Jmeter中逻辑控制器

    1.ForEach控制器 操作如下: 对应结果: 2.if controller(类似于if语句,根据给定表达式的值决定是否执行该节点下的字节的) 3.交替控制器(根据线程组中的循环次数来设定子节点中 ...

  9. 不得不看的秘诀,如何成为一名合格的web前端工程师

    何为:前端工程师? 前端工程师,也叫Web前端开发工程师.他是随着web发展,细分出来的行业. Web前端开发技术主要包括三个要素:HTML.CSS和JavaScript! 它要求前端开发工程师不仅要 ...

  10. 使用Docker搭建apache环境

    Docker搭建apache环境 前言 操作机:ubuntu16 x64 Dockers servion 18.09.7 下载镜像 使用docker pull 拉取最新的 apache镜像 命令:do ...