在决定在自己的项目中使用该工具时,工程师不仅必须研究支持文档,还必须进行一系列实验,以避免将来出现潜在问题。 如果我们谈论的是长期设计的CM策略,那么选择错误的代价就会很高。
本文的目的是练习Git子树管理工具。
从1.7.11版本开始, contrib / subtree目录中的Git上游存储库包含用于自动化处理subtree的工具。
git-subtree(1)服务实际上是有用的附加组件,它使用git-read-tree(1)和git-write-tree(1)函数。 因此, git-subtree(1)中的链接添加/提取/推送命令:
git subtree add --prefix=<subdir> <remote> <ref>
可以是远程存储库的分支名称或标记名称。
另外,如果您预先使用以下命令将远程存储库添加到本地存储库.git / config的配置文件中:
bash-4.4$ git remote add build-system ../../remote/build-system.git
其中build-system是远程存储库../../remote/build-system.git的名称,然后在将来,当使用git-subtree(1)add / pull / push命令时,我们可以引用上游远程/存储库build-system.git的名称。
目前, git-subtree(1)实际上并未开发,而只是针对Git项目的当前开发程度进行了更新。
但是, git-subtree(1)是使用子树的最流行和最强大的工具。
测试环境
在之前的 git-subrepo(1) 文章中 ,我们使用了带有测试存储库的简单目录结构来演示函数在实际中的工作方式。 现在,我们重现以下环境:
bash-4.4$ vim _init.sh
在这里
拥有者 | -- | 项目作者的工作目录; |
遥远的 | -- | 表示项目作者服务器的目录,主项目platform.git和子项目build-system.git的上游存储库位于该目录中 |
使用者 | -- | 用户或开发团队成员的工作目录。 |
作为研究git-subtree(1)功能的目标,我们将考虑Git Subrepo文章中讨论的所有相同任务,但要考虑到这两个工具之间的差异。
连接子树
记住remote / platform.git存储库的当前状态:
bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ git log commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d (HEAD -> master, origin/master) Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
并将上游存储库remote / build-system.git的master分支连接到build-system目录:
bash-4.4$ bash-4.4$ git subtree add --prefix=build-system ../../remote/build-system.git/ master git fetch ../../remote/build-system.git/ master warning: no common commits remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../../remote/build-system * branch master -> FETCH_HEAD Added dir 'build-system' bash-4.4$
考虑remote / platform.git存储库的本地副本的新状态:
bash-4.4$ bash-4.4$ git log --graph * commit 47905bcb80be6f7cb3030513986fad4df548f812 (HEAD -> master) |\ Merge: 7fad4be 783c6d5 | | Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d (origin/master) Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
在这里,您应该注意git-subtree(1)add命令剩下的消息。 实际上,使用此命令,我们将差异存储在平台存储库中:
bash-4.4$ bash-4.4$ git diff 7fad4becbd13258216fb95cbe9d987dd33f0be6d 47905bcb80be6f7cb3030513986fad4df548f812 diff --git a/build-system/README b/build-system/README new file mode 100644 index 0000000..73a41c7 --- /dev/null +++ b/build-system/README @@ -0,0 +1,3 @@ + +[master] build-system 1.0.0 + bash-4.4$
此外,当更改的历史进一步发展时,我们将更详细地研究连接子树的详细信息,现在将更改存储在上游存储库remote / platform.git中 :
bash-4.4$ bash-4.4$ git push Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 582 bytes | 582.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 7fad4be..47905bc master -> master bash-4.4$
并再次查看git-subtree(1)add命令发布:
Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' git-subtree-dir: build-system git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 git-subtree-repo: ../../remote/build-system.git/ git-subtree-ref: master
这些消息很有用,以便在必要时可以找到连接历史记录和子树的当前状态。 原始的git-subtree(1)命令不会添加消息的最后两行。 我们对该实用程序进行了少许修改,以便更轻松地查找有关此项目或该项目的子树在何时以及从远程存储库的哪个分支中创建的信息。
您可以按以下方式获取我们更改的完整差异文件:
bash-4.4$ bash-4.4$ git clone https://github.com/radix-platform/git.git bash-4.4$ cd git bash-4.4$ git checkout git-subtree-2.19.1 bash-4.4$ git diff v2.19.1 > ../git-subtree-2.19.1.patch bash-4.4$
为了使我们的示例更加实际,我们将对上游资源库remote / build-system.git进行更改:
bash-4.4$ bash-4.4$ cd owner/build-system/ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.0.1 bash-4.4$
保存以下更改:
bash-4.4$ bash-4.4$ git add README bash-4.4$ git commit -m "update build-system version to 1.0.1" [master e5c5446] update build-system version to 1.0.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
并将它们传递到远程/ build-system.git上游存储库:
bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git 783c6d5..e5c5446 master -> master bash-4.4$
因此, 构建系统存储库的修订版已从783c6d5更改为e5c5446:
bash-4.4$ bash-4.4$ git log commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 (HEAD -> master, origin/master) Author: user <___@_______> Date: Thu Nov 1 20:26:52 2018 +0300 update build-system version to 1.0.1 commit 783c6d5af1100e9665f930c818c861ff011bed19 Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init build-system master 1.0.0 bash-4.4$
记住这种状态,然后继续使用容器存储库remote / platform.git 。
从上游子树存储库中获取更改
假设我们仍然不知道子树的上游存储库中的更改,并且正在努力改进平台代码:
bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ vim README bash-4.4$ cat README [master] platform 1.0.1 bash-4.4$ bash-4.4$ git add README bash-4.4$ git commit -m "update platform version to 1.0.1" [master 442c9e9] update platform version to 1.0.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 306 bytes | 306.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 47905bc..442c9e9 master -> master bash-4.4$
作为工作的结果,我们获得了remote / platform.git存储库的以下状态:
bash-4.4$ bash-4.4$ git log --graph * commit 442c9e94c9890032fb2f3123661345d465e2849f (HEAD -> master, origin/master) | Author: user <___@_______> | Date: Thu Nov 1 20:41:40 2018 +0300 | | update platform version to 1.0.1 | * commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ Merge: 7fad4be 783c6d5 | | Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
现在,很高兴知道我们在改进项目主存储库中的代码时在构建系统子树的上游存储库中发生了什么。 首先使用git subtree --list命令滚动浏览子树 :
bash-4.4$ bash-4.4$ git subtree --list build-system ../../remote/build-system.git/ branch master HEAD bash-4.4$
该命令以简单的格式显示子树目录,子树上游存储库的URL,链接的类型(分支或标记),链接的名称以及存储库的指定分支或标记的修订版,我们将其代码放入子树中。 但是,我们记得构建系统子项目的开发已经进行了,指向master分支的头部不再有效。 相反,这是关于我们希望在存储库中拥有什么的消息,而不是有关实际情况的消息。
为了找出子树的上游存储库中的代码执行量,我们还需要滚动子树,但需要使用-d选项:
bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$
现在,输出表明在我们处理主存储库的代码时, 构建系统子树的上游存储库的master分支继续进行。 另外, git subtree -d --list命令发出了一个提示,表明我们可以对上游子树存储库进行如下更改:
bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../../remote/build-system * branch master -> FETCH_HEAD hint: Waiting for your editor to close the file...
由于未指定-m“ commit message” ,因此此命令将使用消息文本打开编辑器:
合并提交'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'
#请输入提交消息以说明为什么需要合并,
#特别是如果它将更新的上游合并到主题分支中。
#
#以'#'开头的行将被忽略,并且空消息中止
#提交。
将此文本替换为内容更丰富的文本:
从上游build-system.git存储库的主服务器中提取更改:
合并提交'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'
保存此消息并关闭编辑器后,我们得到以下输出:
Merge made by the 'recursive' strategy. build-system/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
也就是说,我们收到了对上游存储库remote / build-system.git的更改,并将它们保存在主存储库remote / platform.git的本地副本的build-system子树中。
检查本地存储库的状态:
bash-4.4$ bash-4.4$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean bash-4.4$
为了使项目的其他用户能够获得这些更改,我们需要将它们放在上游存储库remote / platform.git中 :
bash-4.4$ bash-4.4$ git push Enumerating objects: 9, done. Counting objects: 100% (8/8), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 583 bytes | 583.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 442c9e9..ea52eab master -> master bash-4.4$
让我们看看平台存储库的本地副本现在包含什么,以及上游存储库remote / platform.git :
bash-4.4$ bash-4.4$ git log --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 | | * | commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ \ Merge: 7fad4be 783c6d5 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
我们看到
remote / build-system.git存储库在作为平台子树连接时的初始状态为
783c6d5af1100e9665f930c818c861ff011bed19 。 但是,当我们在
平台存储库中处理代码时,存储库的状态已更改并变为等于
e5c5446967599065dc02a269d8fcfc2c1d3c4f65 。
构建系统的初始状态( 783c6d5af1100e9665f930c818c861ff011bed19 )在平台存储库的历史记录中处于442c9e94c9890032fb2f3123661345d465e2849f时 。 因此,我们需要以442c9e94c9890032fb2f3123661345d465e2849f的平台状态和e5c5446967599065dc02a269d8fcfc2c1d3c4f65的构建系统状态为基础 ,计算它们之间的差异,并将结果差异叠加在master分支上。
这是合并分支的标准操作,其实质可以表示为
p[n] = p[n-1] + diff(p[n-1], b[n])
在哪里
p[n] = ea52eabd5910159efabd80adcf522f22bf6a2af2, p[n-1] = 442c9e94c9890032fb2f3123661345d465e2849f, b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65.
在这里, p充当master分支,而b充当先前与master分离以便创建新功能的分支。
再次考虑在执行git-subtree-pull命令期间git-subtree(1)实用程序为我们准备的消息:
git subtree pull --prefix=build-system ../../remote/build-system.git/ master
合并提交'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'
#请输入提交消息以说明为什么需要合并,
#特别是如果它将更新的上游合并到主题分支中。
#
#以'#'开头的行将被忽略,并且空消息中止
#提交。
此消息包含对我们重要的信息,即条件
b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65
在“上载 ”到平台存储库的主分支之前, 远程/ build-system.git存储库的主分支位于其中。
当然,在运行git-subtree-pull命令时手动执行提交消息不是很方便,但是,这是向我们传递状态的另一种方法
b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65
在这种情况下, git-subtree(1)实用程序根本不存在。
如果我们使用-m控件
git subtree pill -m "Our own message" ...
则我们将失去状态b [n]的值,并且我们的注释将不会提供任何信息,因此完全无用。
应该注意的是,在构建系统存储库的master分支的状态从47905bcb80be6f7cb3030513986fad4df548f812的原始安装点移开之后 ,我们将始终在查看已连接子树的列表时在remote / build-system.git中接收到更改通知。 换句话说,在命令中使用-d选项:
git subtree -d --list
总是会产生类似于以下内容的消息:
bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$
之所以会发生这种情况,是因为有关连接的子树的所有信息都在与47905bcb80be6f7cb3030513986fad4df548f812一起提交的消息中:
bash-4.4$ bash-4.4$ git show 47905bcb80be6f7cb3030513986fad4df548f812 commit 47905bcb80be6f7cb3030513986fad4df548f812 Merge: 7fad4be 783c6d5 Author: user <___@_______> Date: Thu Nov 1 20:20:20 2018 +0300 Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' git-subtree-dir: build-system git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 git-subtree-repo: ../../remote/build-system.git/ git-subtree-ref: master diff --cc build-system/README index 0000000,0000000..73a41c7 new file mode 100644 --- /dev/null +++ b/build-system/README @@@ -1,0 -1,0 +1,3 @@@ ++ ++[master] build-system 1.0.0 ++ bash-4.4$
并且没有此信息的其他存储库。
唯一的事情是,现在在每次远程/ build-system.git仓库的master分支更新之后,在平台侧,执行命令时
git subtree -d --list
只有字符串的值会改变
remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65
并且我们自己将需要决定是否需要对构建系统子树进行新更改,或者目前不需要。
但是,对于我们来说,按照需要经常执行pull命令并不困难,因为如果remote / build-system.git存储库没有实际更改,则该命令:
git subtree pull --prefix=build-system ../../remote/build-system.git/ master
将给出足够的信息:
bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master From ../../remote/build-system * branch master -> FETCH_HEAD Already up to date. bash-4.4$
用户获取代码
现在,上游资源库remote / platform.git的所有用户都可以使用单个git-pull(1)命令获得完全配置的源树:
bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ bash-4.4$ git pull remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (8/8), done. remote: Total 13 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (13/13), done. From ../../remote/platform 7fad4be..ea52eab master -> origin/master Updating 7fad4be..ea52eab Fast-forward README | 2 +- build-system/README | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 build-system/README bash-4.4$
此外,用户不仅可以跟踪主项目存储库的开发历史,还可以跟踪其所有子树的开发历史:
bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master, origin/HEAD) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
将子树更改交付到上游存储库
记住文件的状态以及平台存储库本身:
bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master, origin/HEAD) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
我们将对构建系统子树进行更改。 为此,请编辑platform / build-system / README文件 :
bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ bash-4.4$ vim build-system/README bash-4.4$ cat build-system/README [master] build-system 1.0.2 bash-4.4$ bash-4.4$ git add build-system/README bash-4.4$ git commit -m "build-system is updated to version 1.0.2 from platform side" [master abaa2c5] build-system is updated to version 1.0.2 from platform side 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
但是我们不会在原始/主平台存储库中记录这些更改。 也就是说,我们将不执行git-push(1)命令,而是直接将git-subtree-push运行到远程/ build-system.git存储库的原始位置:
bash-4.4$ bash-4.4$ git subtree push --prefix=build-system ../../remote/build-system.git/ master git push using: ../../remote/build-system.git/ master Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 290 bytes | 290.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git/ e5c5446..0673142 0673142942ccf53514a276e855a98514952bb713 -> master bash-4.4$
滚动浏览子树,并确保原始remote / build-system.git存储库的HEAD master分支继续进行:
bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: 0673142942ccf53514a276e855a98514952bb713 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$
另外,让我们看一下平台存储库本地副本的状态,记住我们尚未在上游存储库中设置最后一次提交:
bash-4.4$ bash-4.4$ git log -4 --graph * commit abaa2c5edd49dd0cf395c99877b4711d0170af37 (HEAD -> master) | Author: user <___@_______> | Date: Thu Nov 1 21:48:40 2018 +0300 | | build-system is updated to version 1.0.2 from platform side | * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
将更改交付到主项目的上游存储库的正确方法是确保所有子树更改都不会直接进入主存储库,而是来自子树的上游存储库,就像我们使用git-subtree-pull命令接收它们一样。 接下来,我们将说明操作的含义,现在,为了避免后续麻烦,我们将最后一次提交( abaa2c5edd49dd0cf395c99877b4711d0170af37 )还原到平台存储库的本地副本:
bash-4.4$ bash-4.4$ git reset --hard HEAD^ HEAD is now at ea52eab Pull changes from master of upstream build-system.git repository. bash-4.4$
然后从原始的remote / build-system.git上游存储库中“删除”相同的提交。 但首先,请确保我们删除了最后的提交abaa2c5edd49dd0cf395c99877b4711d0170af37 :
bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
, ea52eabd5910159efabd80adcf522f22bf6a2af2 , remote/build-system.git . , , git-subtree-pull :
bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master From ../../remote/build-system * branch master -> FETCH_HEAD hint: Waiting for your editor to close the file...
, :
Merge commit '0673142942ccf53514a276e855a98514952bb713'
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
:
Pull changes from master of origin remote/build-system repository.
Merge commit '0673142942ccf53514a276e855a98514952bb713'
, , :
Merge made by the 'recursive' strategy. build-system/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
, , remote/build-system.git - . , build-system platform , remote/build-system.git :
bash-4.4$ bash-4.4$ git log --graph * commit 04a13bac91d1c445994ffc19db8b479d5e644e17 (HEAD -> master) |\ Merge: ea52eab 0673142 | | Author: user <___@_______> | | Date: Thu Nov 1 21:59:45 2018 +0300 | | | | Pull changes from master of origin remote/build-system repository. | | | | Merge commit '0673142942ccf53514a276e855a98514952bb713' | | | * commit 0673142942ccf53514a276e855a98514952bb713 | | Author: user <___@_______> | | Date: Thu Nov 1 21:48:40 2018 +0300 | | | | build-system is updated to version 1.0.2 from platform side | | * | commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (origin/master) |\ \ Merge: 442c9e9 e5c5446 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 | | * | commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ \ Merge: 7fad4be 783c6d5 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
, , upstream- remote/platform.git .
bash-4.4$ bash-4.4$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean bash-4.4$ bash-4.4$ git push Enumerating objects: 9, done. Counting objects: 100% (8/8), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 600 bytes | 600.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git ea52eab..04a13ba master -> master bash-4.4$
, git-subtree-pull , . , git-push(1) , , , .
, upstream- remote/platform.git 04a13bac91d1c445994ffc19db8b479d5e644e17 , remote/build-system.git , , git-subtree-pull , upstream- remote/platform.git , upstream- remote/platform.git (owner/platform).
git-format-patch
, , git-subtre ,
:
git log -- . ":(exclude)build-system" git log -- build-system
, , .
git-format-patch .
, , patch- ea52eabd5910159efabd80adcf522f22bf6a2af2 , git-format-patch :
bash-4.4$ bash-4.4$ git format-patch ea52eabd5910159efabd80adcf522f22bf6a2af2 --stdout From 0673142942ccf53514a276e855a98514952bb713 Mon Sep 17 00:00:00 2001 From: user <___@_______> Date: Thu, 1 Nov 2018 21:48:40 +0300 Subject: [PATCH] build-system is updated to version 1.0.2 from platform side --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 629b3f4..4fbbbaf 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ -[master] build-system 1.0.1 +[master] build-system 1.0.2 -- 2.19.1 bash-4.4$
, build-system/README build-system/, :
--- a/README +++ b/README
,
git-diff :
bash-4.4$ bash-4.4$ git diff ea52eabd5910159efabd80adcf522f22bf6a2af2 04a13bac91d1c445994ffc19db8b479d5e644e17 diff --git a/build-system/README b/build-system/README index 629b3f4..4fbbbaf 100644 --- a/build-system/README +++ b/build-system/README @@ -1,3 +1,3 @@ -[master] build-system 1.0.1 +[master] build-system 1.0.2 bash-4.4$
patch-:
--- a/build-system/README +++ b/build-system/README
git-diff(1) , , , platform .
政客
CM- , . , , :
, .
, , upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ cd owner/build-system/ bash-4.4$ cat README [master] build-system 1.0.2 bash-4.4$
, upstream- remote/build-system.git , , , minor 1.0.2 . build-system-1.1.x , , : 1.1.0 , 1.1.1 , 1.1.2 , .
:
bash-4.4$ bash-4.4$ git checkout -b build-system-1.1.x Switched to a new branch 'build-system-1.1.x' bash-4.4$ git branch * build-system-1.1.x master bash-4.4$
, README 1.1.0 :
bash-4.4$ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.1.0 bash-4.4$ bash-4.4$ git commit -a -m "Move on to developing 1.1.x functionality" [build-system-1.1.x f6d79c1] Move on to developing 1.1.x functionality 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ git push --set-upstream origin build-system-1.1.x Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git * [new branch] build-system-1.1.x -> build-system-1.1.x Branch 'build-system-1.1.x' set up to track remote branch 'build-system-1.1.x' from 'origin'. bash-4.4$
, , , 1.1.1 :
bash-4.4$ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.1.1 bash-4.4$ bash-4.4$ git commit -a -m "Update build-system version to 1.1.1" [build-system-1.1.x f9544a4] Update build-system version to 1.1.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 276 bytes | 276.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git f6d79c1..f9544a4 build-system-1.1.x -> build-system-1.1.x bash-4.4$
:
bash-4.4$ bash-4.4$ git tag -a 1.1.1 -m "Created tag for release (version 1.1.1)" bash-4.4$ git push origin 1.1.1 Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 170 bytes | 170.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git * [new tag] 1.1.1 -> 1.1.1 bash-4.4$
upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ cd remote/build-system.git/ bash-4.4$ tree refs refs ├── heads │ ├── build-system-1.1.x │ └── master └── tags └── 1.1.1 2 directories, 3 files bash-4.4$
, platform build-system . , , , , platform-1.0.2 :
bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ git branch * master bash-4.4$ git pull Already up to date. bash-4.4$ bash-4.4$ git checkout -b platform-1.0.2 Switched to a new branch 'platform-1.0.2' bash-4.4$ vim README bash-4.4$ cat README [master] platform 1.0.2 bash-4.4$ git commit -a -m "reated platform-1.0.2 branch for the transition to the system 1.1.1" [platform-1.0.2 00a1250] reated platform-1.0.2 branch for the transition to the system 1.1.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
, , - remote/build-system.git , 1.1.1 :
bash-4.4$ bash-4.4$ git rm -rf build-system/ rm 'build-system/README' bash-4.4$ git commit -a -m "Removed subtre based on build-system/master" [platform-1.0.2 7db0f54] Removed subtre based on build-system/master 1 file changed, 3 deletions(-) delete mode 100644 build-system/README bash-4.4$ bash-4.4$ bash-4.4$ git push --set-upstream origin platform-1.0.2 Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 550 bytes | 550.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git/ * [new branch] platform-1.0.2 -> platform-1.0.2 Branch 'platform-1.0.2' set up to track remote branch 'platform-1.0.2' from 'origin'. bash-4.4$ bash-4.4$ bash-4.4$ git subtree add --prefix=build-system ../../remote/build-system.git/ 1.1.1 git fetch ../../remote/build-system.git/ 1.1.1 remote: Enumerating objects: 9, done. remote: Counting objects: 100% (9/9), done. remote: Compressing objects: 100% (3/3), done. remote: Total 7 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (7/7), done. From ../../remote/build-system * tag 1.1.1 -> FETCH_HEAD Added dir 'build-system' bash-4.4$
build-system upstream- remote/platform.git :
bash-4.4$ bash-4.4$ git push Enumerating objects: 12, done. Counting objects: 100% (12/12), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (8/8), 889 bytes | 889.00 KiB/s, done. Total 8 (delta 0), reused 0 (delta 0) To ../../remote/platform.git/ 7db0f54..6f1a50e platform-1.0.2 -> platform-1.0.2 bash-4.4$
:
bash-4.4$ bash-4.4$ git log -3 --graph * commit 6f1a50e249e01f69c54f343b65747d28abc6456d (HEAD -> platform-1.0.2, origin/platform-1.0.2) |\ Merge: 7db0f54 f9544a4 | | Author: user <___@_______> | | Date: Fri Nov 2 18:24:54 2018 +0300 | | | | Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7db0f5452e67086dc4e381a0ccb14f25d48ecf0b | | git-subtree-split: f045926542e9f685034545a45317093383fddf99 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: 1.1.1 | | | * commit f9544a4cc2650a83b96f400fdfc95ba64a38ec6e | | Author: user <___@_______> | | Date: Fri Nov 2 17:59:43 2018 +0300 | | | | Update build-system version to 1.1.1 | | | * commit f6d79c12ada29438454739fe6f6db9592d413be2 | | Author: user <___@_______> | | Date: Fri Nov 2 17:54:35 2018 +0300 | | | | Move on to developing 1.1.x functionality bash-4.4$
, CM- , platform , platform-1.0.2 build-system . , , build-system , .
, upstream- build-system platform , pre-receive
remote/build-system.git/hooks/pre-receive
, , :
. , , , , , , . , , :
git subtree push --prefix=<subdir> <remote> <ref>
<ref> , <subdir> , , (refs/tags/1.1.1), (1.1.1) upstream- ( : refs/heads/1.1.1).
, git-subtree(1) . .
, pre-receive , user/platform/build-system/README:
bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ vim build-system/README bash-4.4$ cat build-system/README [master] build-system 1.1.1 Try to change. bash-4.4$ bash-4.4$ git commit -a -m "Try to change the tag of build-system" [platform-1.0.2 34e7970] Try to change the tag of build-system 1 file changed, 2 insertions(+) bash-4.4$
upstream- remote/build-system.git .
...upstream-
git subtree push --prefix=<subdir> <remote> <ref>
, , , :
bash-4.4$ git subtree -d --list Looking for externals... Commit: 6f1a50e249e01f69c54f343b65747d28abc6456d build-system ../../remote/build-system.git/ tag 1.1.1 f045926542e9f685034545a45317093383fddf99 bash-4.4$
, , upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ git subtree push --prefix=build-system ../../remote/build-system.git/ 1.1.1 git push using: ../../remote/build-system.git/ 1.1.1 Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: ERROR: Trying to change TAG named as 'refs/tags/1.1.1'. remote: To ../../remote/build-system.git/ ! [remote rejected] c3a7333aaa818a7d7a0d501d4b69db1c6a01d40f -> 1.1.1 (pre-receive hook declined) error: failed to push some refs to '../../remote/build-system.git/' bash-4.4$
, , pre-receive , . :
remote: remote: ERROR: Trying to change TAG named as 'refs/tags/1.1.1'. remote:
, , , , :
bash-4.4$ bash-4.4$ git reset --hard HEAD^ HEAD is now at 6f1a50e Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' bash-4.4$
, , platform-1.0.2 :
bash-4.4$ bash-4.4$ git log -3 --graph * commit 6f1a50e249e01f69c54f343b65747d28abc6456d (HEAD -> platform-1.0.2, origin/platform-1.0.2) |\ Merge: 7db0f54 f9544a4 | | Author: user <___@_______> | | Date: Fri Nov 2 18:24:54 2018 +0300 | | | | Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7db0f5452e67086dc4e381a0ccb14f25d48ecf0b | | git-subtree-split: f045926542e9f685034545a45317093383fddf99 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: 1.1.1 | | | * commit f9544a4cc2650a83b96f400fdfc95ba64a38ec6e | | Author: user <___@_______> | | Date: Fri Nov 2 17:59:43 2018 +0300 | | | | Update build-system version to 1.1.1 | | | * commit f6d79c12ada29438454739fe6f6db9592d413be2 | | Author: user <___@_______> | | Date: Fri Nov 2 17:54:35 2018 +0300 | | | | Move on to developing 1.1.x functionality bash-4.4$
git-subrepo , , squashed-, git-subtree(1) , .
, . git-subrepo . , git-subtree , , Git , , , Git .
: