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. MongoDB 走马观花(全面解读篇)

    目录 一.简介 二.基本模型 BSON 数据类型 分布式ID 三.操作语法 四.索引 索引特性 索引分类 索引评估.调优 五.集群 分片机制 副本集 六.事务与一致性 一致性 小结 一.简介 Mong ...

  2. .netCore+Vue 搭建的简捷开发框架 (4)--NetCore 基础 -2

    上节中,我们初步的介绍了一下NetCore的一些基础知识,为了控制篇幅(其实也是因为偷懒),我将NetCore 基础分为两部分来写. 0.WebAPI 项目的建立 1..NetCore 项目执行(加载 ...

  3. Vue核心知识——computed和watch的细节全面分析

    computed和watch的区别 computed特性 1.是计算值,2.应用:就是简化tempalte里面{{}}计算和处理props或$emit的传值,computed(数据联动).3.具有缓存 ...

  4. Cheapest Palindrome POJ - 3280

    Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate ...

  5. Flask中的CBV以及正则表达式

    Flask中的CBV以及正则表达式 一.CBV def auth(func): def inner(*args, **kwargs): print('before') result = func(*a ...

  6. “零基础”如何快速掌握web前端核心技术?

    前端开发要学的知识内容涉及的会很宽泛,虽然说主要是HTML.CSS和JavaScript这些基础知识点,今天想强调一下,学前端开发除了要学这些基础知识外,学员还要在这之上进行延伸和深入的去学,而且互联 ...

  7. Msfvenom命令总结大全

    1.    –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...

  8. UVA10228 A Star not a Tree?

    [返回模拟退火略解] 题目描述 一平面上有 nnn 个点 {Ai}\{A_i\}{Ai​},求一个点 XXX 使得σ=∑i=1ndis(Ai,X)\sigma=\sum_{i=1}^{n}{dis(A ...

  9. redis内存数据的持久化方式

    转: http://blog.csdn.net/wzqzhq/article/details/64920996 概述 Redis的强大性能很大程度上都是因为所有数据都是存储在内存中的,然而当Redis ...

  10. 《Java并发编程实战》读书笔记-第3章 对象的共享

    可见性 在没有同步的情况下,编译器.处理器以及运行时都可能做指令重排.执行结果可能会出现错误 volatile变量 编译器与运行时不会进行指令重排,不会进行缓存,使用volatile变量要满足以下条件 ...