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. WebSocket协议与抓包

    WebSocket协议 WebSocket并不是全新的协议,而是利用了HTTP协议来建立连接,它的目的是在浏览器和服务器之间建立一个不受限的双向通信的通道,比如说,服务器可以在任意时刻发送消息给浏览器 ...

  2. 软件开发工具(第12章: CVS的安装及使用)

    一.CVS介绍 并发版本系统(Concurrent Versions System——CVS)是一个常用 的代码版本控制系统. 使用CVS可以对代码进行集中管理,记录代码所有的更改历史,提供 协作开发 ...

  3. 基于Influxdb对InfluxDBResultMapper的一点扩展

    理想很饱满,现实很骨感. 由于业务需要"灵活可配置"的功能需求,在使用java开发Influxdb查询功能的时候,遇到了一个问题,Measurement注解的名称有可能需要动态变化 ...

  4. 控制器向视图传参ModelAndView、Model和Map

    ModelAndView类 ModelAndView在spring-webmvc-4.3.18.RELEASE.jar包下,当然其他版本也有,所在包如下 对于那些返回String等类型的处理方法,sp ...

  5. 11g bug event 'cursor: mutex S'-引发的CPU冲高问题

    问题背景:客户反应数据库服务器CPU占用过高 1> 确认问题根源登录客户DB服务器: top 查看当前负载 (几乎100%)top - 10:47:55 up 29 days, 21:51, 3 ...

  6. Elasticsearch 7.x 之文档、索引和 REST API 【基础入门篇】

    前几天写过一篇<Elasticsearch 7.x 最详细安装及配置>,今天继续最新版基础入门内容.这一篇简单总结了 Elasticsearch 7.x 之文档.索引和 REST API. ...

  7. Django2.1.3 urls.py path模块配置

    learning_log/urls.py learning_logs/urls.py django2.0和1.x的区别是非常明显的,2.0开始使用path和re_path代替原来的url,而且用法有了 ...

  8. 最新2019Pycharm安装破解教程!内附破解码!

    本教程仅用作个人学习,请勿用于商业获利,造成后果自负!!! Pycharm安装 在这插一个小话题哈,Pycharm只是一个编译器,并不能代替Python,如果要使用Python,还是需要安装Pytho ...

  9. Python中的可变对象与不可变对象、浅拷贝与深拷贝

    Python中的对象分为可变与不可变,有必要了解一下,这会影响到python对象的赋值与拷贝.而拷贝也有深浅之别. 不可变对象 简单说就是某个对象存放在内存中,这块内存中的值是不能改变的,变量指向这块 ...

  10. Flask中的flash

    一.简单的使用 - 必须要设置秘钥因为flash是基于session -设置:flash('aaa') -取值:get_flashed_message() #从源码我们可以看出get_flashed_ ...