git-合并到 public 裸仓库中

git-merge In public bare repos

GitHub and GitLab provide ways to merge branches directly in their web interface. Given that those sites store only bare repos, how do they perform those merges? Can the same thing be done on the command line in a bare clone? I found this 这样的站点作为使用管道命令的可能答案。

因为GitHub是闭源的,我们不能确定他们的后端如何处理合并操作。然而,GitLab开源的,我们可以查看实现细节,随着时间的推移发生了变化。

GitLab 是如何做到的

今天,UI 中出现的大多数 git 相关功能,包括 GitLab 上的 git 合并由 gitaly component of GitLab, which interacts with the physical storage of git repositories. It primarily uses its dependent library, git2go 处理,用于执行实际 git 操作。

仔细查看 gitaly 的源代码,我能做出的最佳评估是 git 实际上 确实 广泛使用了工作树git 操作,包括合并。存储库和工作树通常被打开并克隆到“隔离”目录,这些目录只是即时创建的临时目录,存储库的工作树被克隆到临时目录。 (参见 quarantine.go#L40-58, called from merge.go#L53)。

how do they perform those merges?

所以,回答你的问题:至少在 GitLab 中,工作树 用于合并(以及其他操作)并且 不是裸露的存储库。 您只是看不到它们,因为在将它们提交到实际存储库路径之前使用了临时目录。

我们或许可以假设 GitHub 做了类似的事情,但不可能确定。

能做到吗?

Can the same thing be done on the command line in a bare clone?

您指出了一个示例,似乎 在没有检查工作树的情况下工作?但它是通过写出树(使用 git write-tree)来工作的,这在实际层面上似乎没有任何优势,比如从裸仓库克隆并检查工作树并使用 git 正常运作。为了性能(预期可能的反对意见),您可以使用 tempfs 或其他一些内存映射位置。

我也不确定链接的答案是否足以执行 git merge 使用的各种合并策略。

那么,就技术性而言,也许吧?您链接的答案似乎很好地回答了这个问题。从实用层面上说会很有用,不,好像不是。