简体   繁体   English

分布式版本控制系统的分散行为如何工作?

[英]How do the decentralized behaviour of Distributed Revision Control Systems Work?

I wonder how do the decentralized DVCS's work? 我想知道分散的DVCS是如何工作的? If there is no central server how can a developer machine knows and syncs the repository with the other developer machines' repositories. 如果没有中央服务器,开发人员机器如何知道并将存储库与其他开发人员机器的存储库同步。 And how does the changes are merged? 这些变化是如何合并的? Because lack of central server seems like to me the system might cause each repository have a different revision numbers. 由于缺乏中央服务器似乎对我来说系统可能会导致每个存储库都有不同的版本号。 And how does the conflict resolutions are handled? 如何处理冲突解决方案?

Scott Chacon's presentation from RailsConf last year was terrific. Scott Chacon去年在RailsConf上的演讲非常棒。 One of the best planned out and informational talks that I have ever seen. 我见过的最好的计划和信息谈话之一。 I'll defer to him (specifically, for your question, the remote workflow part starts around 18 minutes into it): 我会推荐给他(特别是,对于你的问题,远程工作流程部分开始大约18分钟):

RailsConf Git Talk RailsConf Git Talk

I'm partial to Git, but I believe the theory applies to most other systems... 我偏爱Git,但我相信这个理论适用于大多数其他系统......

Decentralized VCS is designed to handle branching and merging as part of its DNA by keeping a pointer to the previous commit in every commit, so any change can be traced back to a common ancestor. 分散式VCS旨在通过在每次提交中保持指向前一次提交的指针来处理分支和合并作为其DNA的一部分,因此任何更改都可以追溯到共同的祖先。

Revision "numbers" as such aren't used to refer to commits. 修订版“数字”本身并不用于指代提交。 Obviously, there would be more than one sequence if that were the case... In the case of Git, the pointer "key" which uniquely identifies any commit is an SHA1 hash. 显然,如果是这样的话会有不止一个序列......在Git的情况下,唯一标识任何提交的指针“key”是SHA1哈希。 The only thing that makes the whole arrangement sequential is the graph of pointers referencing each commit's parent. 使整个排列顺序的唯一因素是引用每个提交的父级的指针图。

In practice, a developer commits their work to their own local copy, and when it's time to share it with others, they do so in three ways: 在实践中,开发人员将他们的工作提交给他们自己的本地副本,当他们与其他人共享时,他们会以三种方式这样做:

  • Ask the other developer to pull the changes directly from them 请其他开发人员直接从他们那里获取更改
  • Push directly into the other developer's copy 直接推送到其他开发人员的副本
  • Push the changes to a central location that others can pull from 将更改推送到其他人可以拉出的中心位置

These are really the same thing in the end because it just comes down to merging the diffs. 这些实际上最终是相同的,因为它归结为合并差异。 In the third scenario the central location merely acts as a proxy--the same thing can be achieved without it. 在第三种情况下,中心位置仅仅作为代理 - 没有它就可以实现同样的目标。

The system can be as centralized or decentralized as you choose to make it. 系统可以像您选择的那样集中或分散。 Most projects have some amount of centralization for practical reasons, but at any point a fork can become the new central repository, or developers can choose to trade code between themselves ad-hoc. 由于实际原因,大多数项目都有一定程度的集中化,但是在任何时候,fork都可以成为新的中央存储库,或者开发人员可以选择在它们之间自行交换代码。

When commits are fetched and merged into your own copy, these are applied on top of whatever common ancestor you share with the upstream repository. 当提交提交并合并到您自己的副本中时,这些提交应用于您与上游存储库共享的任何共同祖先。 If there is a conflict, the merge process pauses at the commit step where the conflict occurred, and asks you to resolve it before continuing to apply the remaining commits on top of it. 如果存在冲突,则合并进程会在发生冲突的提交步骤暂停,并要求您在继续在其上应用剩余提交之前解决它。 (Standard unified diff markers are used to mark the conflicts.) (标准统一差异标记用于标记冲突。)

Most merges happen automatically, but when there's a conflict it's often quite trivial to resolve. 大多数合并都会自动发生,但是当发生冲突时,解决这个问题通常都很简单。 The nice thing is that you don't end up with a ball of conflicts spanning several commits: it's much easier to resolve because it pauses in the middle of the history and lets you deal with it in smaller, logical chunks. 好的一点是,你最终不会遇到几个提交的冲突球:它更容易解决,因为它在历史中间暂停,让你以较小的逻辑块处理它。

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

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