我刚刚发现git-subtree工具,它在一段时间前成为了主git代码库的一部分 https://github.com/apenwarr/git-subtree/
然而,我并不完全理解这个工具提供了什么功能,相比于已经存在的“git read-tree”+ “git merge -s subtree”。git-subtree的唯一目的是使最终提交历史看起来更好,还是有其他的功能我忽略了呢?
我刚刚发现git-subtree工具,它在一段时间前成为了主git代码库的一部分 https://github.com/apenwarr/git-subtree/
然而,我并不完全理解这个工具提供了什么功能,相比于已经存在的“git read-tree”+ “git merge -s subtree”。git-subtree的唯一目的是使最终提交历史看起来更好,还是有其他的功能我忽略了呢?
您描述的命令将子树读入存储库中。如文档所述,git-subtree
命令还有许多其他选项。其中包括(为简单起见进行了注释):
add::
Create the <prefix> subtree by importing its contents
from the given <refspec> or <repository> and remote <refspec>.
merge::
Merge recent changes up to <commit> into the <prefix>
subtree.
pull::
Exactly like 'merge', but parallels 'git pull' in that
it fetches the given commit from the specified remote
repository.
push::
Does a 'split' (see above) using the <prefix> supplied
and then does a 'git push' to push the result to the
repository and refspec. This can be used to push your
subtree to different branches of the remote repository.
split::
Extract a new, synthetic project history from the
history of the <prefix> subtree. The new history
includes only the commits (including merges) that
affected <prefix>, and each of those commits now has the
contents of <prefix> at the root of the project instead
of in a subdirectory. Thus, the newly created history
is suitable for export as a separate git repository.
此外还有各种标志可以辅助和操作上述过程。我相信所有这些选项在之前都可以通过一系列管道命令来使用。git-subtree.sh
只是将它们封装起来,使它们更容易执行。
git subtree
还考虑了 Git 配置。git subtree pull
,请确保使用 Git 2.36+。git subtree
想要创建合并时,它使用 "git merge
"(man) 并让其受到最终用户的 "merge.ff
" 配置的影响。这个问题已经在 Git 2.36(2022 年第二季度)得到了修正。koutcher
)。gitster
--在提交0ac270c中合并,于2022年2月17日)
subtree
:强制合并提交签署者:Thomas Koutcher
审查者:Johannes Altmanninger
When
merge.ff
is set toonly
in.gitconfig
,git subtree pull
will fail with errorfatal: Not possible to fast-forward, aborting.
But the command does want to make merges in these places.
Add
--no-ff
argument togit merge
(man) to enforce this behaviour.