我如何保持git repo的子文件夹与另一个git repo的子文件夹同步 [英] How can I keep a subfolder of a git repo in sync with a subfolder of another git repo
问题描述
我有两个git项目。一个取决于另一个存储库的子文件夹。
以下是设置文件夹的方式。
repoA
.git
folderA1 /
folderA2 /
repoB
.git
folderB1 /
folderB1 / folderB11
folderB2 /
我想达到的是以下内容:
repoA
.git
folderA1 /
folderA2 /
folderB11<<<<<这映射到分支名称blah上的repoB
repoB
.git
folderB1 /
folderB1 / folderB11
folderB2 /
在 repoA
中,folderA1中的某些文件可能会引用folderB11中的文件。 repoA
包含引用 folderB11
中的文件的python模块。同样, repoB
还包含引用 folderB11
中的文件的python模块。
我看着git子树,但它似乎没有同步这两个文件夹。
一个选项是创建 folderB11
作为存储库,并为其添加一个子树到 repoA
和 repoB
,但我宁愿没有第三个存储库,因为维护代码会很麻烦。此外,将第三个存储库作为 folderB11
应位于 repoB
中以确保准确性并不是理想的选择。其他项目。
有没有办法将git repo的子文件夹与另一个git repo的子文件夹同步?
符号链接或子模块的两个替代方法的一个问题是,您没有获得任何一致的历史记录
repoA
或repoB
在一个存储库中。
使用 submodule ,因为它记录在父回购库( repoA
)中,所以 repoB
已使用。
将它记录为 gitlink (索引中的特殊条目)。
< blockquote>
它们创建一个必须跟踪和管理的外部依赖项。
这就是子模块为你所做的事情。
如果您想回到
repoA
的旧提交,您必须跟踪并知道repoB中相应的提交是什么
。
再次,子模块记录该信息。
返回旧版本的 repoA
,做一个 git子模块更新--init
和你的 repoB
处于连贯状态,在右侧sha1。
I have two git projects. One depends on a subfolder of another repository.
Here's how the folders are setup.
repoA
.git
folderA1/
folderA2/
repoB
.git
folderB1/
folderB1/folderB11
folderB2/
What I want would like to achieve is the following
repoA
.git
folderA1/
folderA2/
folderB11 <<<< This maps to the repoB on branch name "blah"
repoB
.git
folderB1/
folderB1/folderB11
folderB2/
In repoA
, some files in folderA1 might reference the ones in folderB11. repoA
contains python modules that reference files in folderB11
. Similarly, repoB
also contains python modules that reference files in folderB11
.
I looked at git subtree, but it doesn't appear to sync both folder.
One option is to create folderB11
as a repository and add it a subtree to repoA
and repoB
, but I would rather not have a third repository as it's going to be a pain to maintain the code. Also, it's not ideally an option to have a third repository as folderB11
should be located in repoB
to ensure accuracy with the rest of the project.
Is there a way to synchronize a subfolder of a git repo with a subfolder of another git repo?
One problem with both alternatives of symlinks or submodules is that you don't get a coherent history for either
repoA
orrepoB
in a single repository.
With submodule, it does, since it records in parent repo (repoA
) the exact SHA1 of the repoB
used.
It records it as a gitlink (a special entry in the index).
They create an external dependency which has to be tracked and managed.
That is what submodule does for you.
If you want to go back to an old commit of
repoA
, you'd have to track and know what was the corresponding commit inrepoB
.
Again, submodule records that information.
Go back to an old version of repoA
, do a git submodule update --init
and your repoB
is in a coherent state, at the right sha1.
这篇关于我如何保持git repo的子文件夹与另一个git repo的子文件夹同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!