【Git官方文档翻译】1. 新手入门

来源:互联网 发布:男士发簪 淘宝 编辑:程序博客网 时间:2024/05/20 03:44

1.1 新手入门 - 关于版本控制

本章将讲述如何入门Git。我们将讲述一下版本控制工具的背景作为开始,然后我们将继续说明怎样在你的系统运行Git 并且最终让它运行起来并且使用它。最后,在本章最后你应该明白为什么Git会这么流行,为什么你应该使用它,为什么你应该立即使用它。

关于版本控制

什么事“版本控制”呢,你为什么要关心这个问题呢?版本控制是记录文件变化的系统并且随后你可以将文件回滚到一个特定的版本,例如在本书所展示的示例中,我们只是对保存软件源代码的文本文件进行版本控制管理,但实际上,你可以对任何类型的文件进行版本控制。


如果你是一个图形设计师或者网站设计师并且想保存每个版本的图片和布局(这也许是你最想要的功能),使用一个版本控制系统(Version Control System,VCS)将会是一个明智的选择。它允许你将文件退回到之前的状态,退回整个工程到之前的状态,比较文件的变化细节,查出最后是谁修改了哪个地方,从而找出导致怪异问题出现的原因。谁引入了问题,何时引入了问题以及其他的更多功能使用版本控制系统通常也意味着你弄坏了文件或者删除了文件,你可以轻松的恢复。除此之外,你可以用极少的额外工作开销达到这种效果。

本地版本控制系统

许多人的版本控制方法是复制文件到另外的路径(如果他们足够聪明,或许还会使用时间进行标注),这么做唯一的好处就是简单。当你向拷贝 文件的时候很容易发生一些意外,也许你会忘掉你想要保存的路径,一旦弄错文件丢了数据就没法撤销恢复。为了解决这个问题,工程师在很久之前开发了本地版本控制VCS,它拥有小型的数据库,能够保存在版本控制下的所有的变化

Local version control diagram
图 1-1. 本地版本控制.
有一个更流行的版本控制系统叫做RCS,今天仍然在许多分布在许多电脑中。甚至是流行的Mac OSX安装了开发工具后,也可以使用 rcs 命令。它的工作原理基本上可以说是保存并管理文件补丁(patch)。文件补丁是一种特殊格式的文本文件,记录着相应文件修订前后的内容变化。所以,根据每次修订后的补丁,rcs 可以通过不断打补丁,计算出各个版本的文件内容。


集中化的版本控制系统


人们接下来遇到的主要的问题是人们需要在系统中协同工作 。为了解决这个问题, 开发出了集中化的版本控制系统(Centralized Version Control Systems (CVCSs) .例如CVS,Subversion和Perfoce这些系统拥有一个服务器,服务器中包含了所有版本的文件,而协同工作的人们都通过客户端连到这台服务器,取出最新的文件或者提交更新的内容。很多年以来,这已成为版本控制系统的标准做法。

Centralized version control diagram
图片 1-2. 集中化的版本控制系统

This setup offers many advantages, especially over local VCSs. For example, everyone knows to a certain degree what everyone else on the project is doing. Administrators have fine-grained control over who can do what; and it’s far easier to administer a CVCS than it is to deal with local databases on every client.

However, this setup also has some serious downsides. The most obvious is the single point of failure that the centralized server represents. If that server goes down for an hour, then during that hour nobody can collaborate at all or save versioned changes to anything they’re working on. If the hard disk the central database is on becomes corrupted, and proper backups haven’t been kept, you lose absolutely everything – the entire history of the project except whatever single snapshots people happen to have on their local machines. Local VCS systems suffer from this same problem – whenever you have the entire history of the project in a single place, you risk losing everything.

Distributed Version Control Systems

This is where Distributed Version Control Systems (DVCSs) step in. In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don’t just check out the latest snapshot of the files: they fully mirror the repository. Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data.

Distributed version control diagramFigure 1-3. Distributed version control.

Furthermore, many of these systems deal pretty well with having several remote repositories they can work with, so you can collaborate with different groups of people in different ways simultaneously within the same project. This allows you to set up several types of workflows that aren’t possible in centralized systems, such as hierarchical models.

0 0
原创粉丝点击