简体   繁体   English

Git 子树拉取导致合并冲突

[英]Git subtree pull results in merge conflict

Currently I have 3 repositories, named A, B, and C. Both A and B have a folder called c which is a subtree of repository C. Now, when I add a new file to A's c, do a git add, commit and a git subtree push, it gets pushed to C. When I do a pull in B, it ends up in B's c folder, so that works like expected.目前我有 3 个存储库,名为 A、B 和 C。A 和 B 都有一个名为 c 的文件夹,它是存储库 C 的子树。现在,当我向 A 的 c 添加一个新文件时,执行 git 添加、提交和git 子树推送,它被推送到 C。当我拉入 B 时,它最终出现在 B 的 c 文件夹中,因此它按预期工作。 But when I then edit the new file in B's c and do a git commit and git subtree push and I do a git subtree pull in A, I get a merge conflict.但是当我然后在 B 的 c 中编辑新文件并执行 git 提交和 git 子树推送并且我在 A 中执行 git 子树拉入时,我遇到了合并冲突。

How do I prevent this conflict?我如何防止这种冲突?

I was curious (perhaps suspicious) about whether this part of your description might be relevant.我很好奇(也许是怀疑)你的这部分描述是否相关。 You said "Currently I have 3 repositories, named A, B, and C. Both A and B have a folder called c which is a subtree of repository C ."你说“目前我有 3 个存储库,分别命名为 A、B 和 C。A 和 B 都有一个名为 c 的文件夹,它是存储库 C 的子树。”

When I work with subtrees, the shared subtree is hosted by a bare repository that is entirely devoted to that shared subtree content.当我使用子树时,共享子树由一个完全专用于该共享子树内容的裸存储库托管。 So, if one wants to have a shared folder f, then there is a bare repository F that holds all the files that would go into the shared folder f and nothing else.因此,如果想要一个共享文件夹 f,则有一个裸存储库 F,其中包含将 go 放入共享文件夹 f 的所有文件,仅此而已。 The F repository doesn't have other content. F 存储库没有其他内容。 It wouldn't have a folder f as a portion of the F repository.它不会将文件夹 f 作为 F 存储库的一部分。 The F repository is bare (no working tree content). F 存储库是空的(没有工作树内容)。

Then, if I have three projects, A, B, and C, that all want to use folder f, that folder f is contained in each of A, B, and C as a subtree and all three will pull from and push to the bare repository F. F is the hub and the others (A, B, and C) are spokes.然后,如果我有三个项目,A、B 和 C,它们都想使用文件夹 f,则文件夹 f 作为子树包含在 A、B 和 C 中,所有三个都将从裸存储库 F。F 是中心,其他(A、B 和 C)是辐条。 Each spoke exchanges with the hub, but not directly with each other.每个辐条与集线器交换,但不直接相互交换。 A and B don't push to or pull from C, for example.例如,A 和 B 不会推入或拉出 C。

From your description, that would be my best guess about what might be leading to your problem.根据您的描述,这将是我对可能导致您出现问题的原因的最佳猜测。 Try making sure that the central host repository of the subtree is only a bare repository that is not used to hold anything else or any working tree content.尝试确保子树的中央主机存储库只是一个裸存储库,不用于保存任何其他内容或任何工作树内容。

ps While I do have a local bare repository to host the shared subtree (which allows working even when not connected to the inte.net -- a foundational benefit of distributed version control), one can also periodically push the changes in the updated local bare repository to a remote bare repository for safe keeping. ps 虽然我确实有一个本地裸存储库来托管共享子树(即使在未连接到 inte.net 时也可以工作——分布式版本控制的基本好处),但也可以定期推送更新的本地裸存储中的更改存储库到远程裸存储库以便安全保存。 However, in this configuration, I don't recommend trying to have multiple developers make independent changes to the same shared subtree.但是,在此配置中,我不建议尝试让多个开发人员对同一共享子树进行独立更改。 If you have multiple developers working on the shared subtree code, then just use one shared remote bare repository at whatever service you use for shared remote repositories.如果您有多个开发人员在共享子树代码上工作,那么只需在您用于共享远程存储库的任何服务上使用一个共享远程裸存储库。

Extra tip: IF one is working with a local bare repository (because of working with a subtree), that can be less than ideal because there is (so far) poor support for working with a local bare repository on your computer.额外提示:如果一个人正在使用本地裸存储库(因为使用子树),那可能不太理想,因为(到目前为止)对在您的计算机上使用本地裸存储库的支持很差。 While in a Windows environment with Git for Windows, if I cd into the top directory of the bare repository, then the gitk command will bring up a usable gui tool that lets one examine the bare repository.在 Windows 环境中,Git 为 Windows,如果我进入裸存储库的顶层目录,则gitk命令将调出一个可用的 gui 工具,让人们可以检查裸存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM