为什么 git 被称为分布式源代码控制系统?
似乎在将代码提交到本地存储库后,每个程序员都会运行该命令。
git push origin master
将本地文件推送到某个远程服务器。 除了本地副本之外,它与客户端/服务器模型没有什么不同,那么为什么它被称为“分布式”模型呢?
It seems after committing code to the local repository, every programmer will run the command.
git push origin master
to push the local file to a certain remote server.
It is not different with client/server model except a local copy, so why is it called a "distributed" one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
简答
在下图中,alice 和 david 可以交互,因为系统是分布式的。
分布式版本控制
请注意 alice 和 david 可以交互,因为每个都可以充当服务器。
中央版本控制
这里是开发者团队仅与主服务器交互。
长答案
传统上,源代码控制系统被设计为服务器-客户端设置,松散地说。所以存储库位于中心。
借助 git 和 Mercurial,该系统旨在让所有用户处于平等地位。 每个人都拥有完整的存储库。以这种方式控制和存储库分布在用户之间。
Short Answer
In the diagram below alice and david can interact because the system is distributed.
Distributed Version Control
Notice how, say, alice and david can interact because each can act as a server.
Central Version Control
Here the dev team only interacts with the main server.
Long Answer
Traditionally speaking source control systems were designed as server-client setups, loosely speaking. So the repository was centrally located.
With git and Mercurial, the system is designed to put all users at equal footing. Everyone has the full repository with them. The control and repository in that way is distributed amongst it users.
CVS 和 SVN 等工具提供了集中式存储库模型。每个人都将他们的更改提交到同一个中央存储库。每个提交者都保留中央存储库最新版本的副本。当他们提交更改时,他们会将更改发送回主存储库。
这里的限制是您始终需要在本地存储库上拥有最新的代码,并且要查看更改的历史记录,您需要向服务器询问该信息。您还始终需要能够访问远程存储库才能提交。
分布式 SCN 可以模拟此模型,但它提供的功能远不止于此。每个提交者都拥有自己的存储库,其中包含项目的整个提交历史记录,而不是只有一个用于将更改发送到的中央存储库。您不需要连接到远程存储库,更改只会记录在本地存储库中。您仍然可以推送到集中存储库,但您不需要。
(来源:Travis Swicegood 的使用 Git 进行实用版本控制)
一这样做的一大好处是您可以随时在本地计算机上启动存储库。一般来说,当我开始一个新项目时,我会
git init
并立即开始提交更新。稍后,如果我决定与其他开发人员共享该项目,我可以轻松设置一个我们都可以访问的集中存储库。或者它可能永远不会离开我的计算机,但我将拥有本地版本控制,并且可以轻松查看我的提交历史记录。另一个很大的好处(对于现在的云计算来说可能不那么明显)是冗余。如果存储库的一个副本由于某种原因丢失,任何其他存储库都将包含完整的历史记录,因此您可能会丢失自上次
推送
以来的任何工作。维基百科上有更多信息:分布式修订控制
我还强烈推荐上述实用程序员关于 Git 的书。
Tools such as CVS and SVN offer a centralised repository model. Everybody commits their changes to the same central repository. Each committer keeps a copy of the latest version of the central repository. When they commit changes they send that change back to the main repository.
The limitations here are that you always need to have the latest code on your local repository, and to see the history of changes you will need to ask the server for that information. You also always need to be able to access the remote repository to commit.
A distributed SCN can emulate this model, but it offers so much more. Instead of just having one central repository that you send changes to, every committer has their own repository that has the entire commit history of the project. You don't need to connect to a remote repository, the change is just recorded on your local repository. You can still push to a centralised repository but you don't need to.
(Source: Pragmatic Version Control using Git by Travis Swicegood)
One big benefit of this is that you can start a repository at any time on your local computer. Generally when ever I start a new project I'll
git init
and start committing updates straight away. Later on if I decide I want to share this project with another developer I can easily set up a centralised repository that we can both access. Or it might never leave my computer but I'll have local version control in place and can easily view my commit history.Another big benefit (perhaps less so with cloud computing now) is redundancy. If one copy of the repository is lost for whatever reason, any of the other repositories will contain the complete history so you could only potentially lose any work since your last
push
.There's some more information on Wikipedia: Distributed revision control
I'd also highly recommend the above mentioned Pragmatic Programmers book on Git.
因为您的克隆可以是其他人的主控,并且您可以将您的克隆推送到任何其他存储库。不需要一个“真正的”大师的概念;您可以将其作为分布式存储库网格运行。
Because your clone can be someone else's master, and you can push your clone towards any other repository. There is no need for a concept of one "true" master; you can run it as a distributed grid of repositories.
之所以称为分布式,是因为每个 git 工作目录都包含一个完整的存储库,其中包含树的完整历史记录。这也意味着您实际上不需要网络访问来进行开发,因为您的树本质上可以是主树。
It is called distributed because every git working directory contains a full-fledged repository containing complete history of the tree. This also means that you actually do not need network access for development because your tree can essentially be the master tree.
查看分布式系统的定义,并将其与 Git 所做/允许完成的操作进行比较。我认为有一场比赛。根据定义,客户端/服务器方法需要一个“最终/参考副本”,而 Git 和类似方法的情况并非如此。
Check out the definition of a distributed system and compare that to what Git does/allows to be done. I think there's a match. A client/server approach needs by definition one "definitive/reference copy" which is not the case with Git and similar.