我已经使用Subversion很多年了,在使用SourceSafe之后,我爱上了Subversion。结合TortoiseSVN,我真的无法想象它还能有什么更好的。

然而,越来越多的开发人员声称Subversion存在问题,我们应该转向新的分布式版本控制系统,比如Git。

Git如何改进Subversion?


当前回答

来自SourceGear的Eric Sink写了一系列关于分布式和非分布式版本控制系统之间区别的文章。他比较了最流行的版本控制系统的优缺点。非常有趣的读物。 文章可以在他的博客www.ericsink.com上找到:

阅读差异 Git是版本控制工具中的C Git缺乏对不变性和DVCS最佳实践的尊重 DVCS和dag,第1部分 DVCS和dag,第2部分 DVCS和Bug跟踪 合并历史,dag和Darcs Git为什么这么快? Mercurial, Subversion和Wesley Snipes

其他回答

Easy Git有一个很好的页面,比较了Git和SVN的实际使用情况,这将让你了解Git可以做什么(或更容易做什么)。(从技术上讲,这是基于Easy Git的,它是Git之上的轻量级包装器。)

Git并不比Subversion好。但也不是更糟。这是不一样的。

关键的区别在于它是去中心化的。想象一下你是一个在路上的开发人员,你在你的笔记本电脑上开发,你想要有源代码控制,这样你就可以回到3小时前。

使用Subversion时,您会遇到一个问题:SVN存储库可能位于您无法到达的位置(在您的公司中,并且您目前没有互联网),您无法提交。如果你想复制你的代码,你必须复制/粘贴它。

使用Git,您就不会遇到这个问题。您的本地副本是一个存储库,您可以提交它并获得源代码控制的所有好处。当您重新获得到主存储库的连接时,您可以针对它提交。

一开始看起来不错,但是要记住这种方法增加了复杂性。

Git似乎是“新的、闪亮的、酷的”东西。它绝对不坏(毕竟Linus为Linux内核开发写了它是有原因的),但是我觉得很多人只是因为它是新的并且是由Linus Torvalds写的,就跳上了“分布式源代码控制”这列火车,而不知道为什么/它是否更好。

Subversion有问题,但是Git、Mercurial、CVS、TFS等等也有问题。

编辑:所以这个答案现在已经有一年了,仍然获得了很多赞,所以我想我会添加更多的解释。在写这篇文章后的去年,Git获得了很多动力和支持,特别是在像GitHub这样的网站真正起飞之后。我现在同时使用Git和Subversion,我想分享一些个人见解。

First of all, Git can be really confusing at first when working decentralized. What is a remote? and How to properly set up the initial repository? are two questions that come up at the beginning, especially compared to SVN's simple "svnadmin create", Git's "git init" can take the parameters --bare and --shared which seems to be the "proper" way to set up a centralized repository. There are reasons for this, but it adds complexity. The documentation of the "checkout" command is very confusing to people changing over - the "proper" way seems to be "git clone", while "git checkout" seems to switch branches.

当你去中心化的时候,Git真的会发光。我家里有一台服务器,路上有一台笔记本电脑,SVN在这里根本不能很好地工作。使用SVN,如果我没有连接到存储库,我就不能进行本地源代码控制(是的,我知道SVK或复制回购的方法)。对于Git,这是默认模式。这是一个额外的命令(git commit在本地提交,而git push origin master将主分支推到名为“origin”的远程)。

如上所述:Git增加了复杂性。创建存储库的两种模式,签出vs克隆,提交vs推…您必须知道哪些命令在本地工作,哪些命令在“服务器”上工作(我假设大多数人仍然喜欢中央的“主存储库”)。

而且,工具仍然不够,至少在Windows上是这样。是的,有一个Visual Studio插件,但我仍然使用git bash和msysgit。

SVN的优点是学习起来简单得多:有您的存储库,所有针对它的更改,如果您知道如何创建、提交和签出,您就可以准备好,并可以在以后提取分支、更新等内容。

Git的优势在于,如果一些开发人员不总是连接到主存储库,它会更适合。而且,它比SVN快得多。据我所知,分支和合并支持要好得多(这是意料之中的,因为这是编写它的核心原因)。

这也解释了为什么它在互联网上获得了如此多的关注,因为Git非常适合开源项目:只需Fork它,将您的更改提交到您自己的Fork,然后让原始项目维护者提取您的更改。使用Git,这就可以了。真的,在Github上试试吧,太神奇了。

我还看到了Git-SVN网桥:中央存储库是一个Subversion repo,但开发人员在本地使用Git,网桥将他们的更改推到SVN。

但是即使有了这么长的补充,我仍然坚持我的核心信息:Git并没有更好或更差,它只是不同而已。如果你需要“离线源代码控制”,并愿意花一些额外的时间学习它,那就太棒了。但是如果您有一个严格集中的源代码控制,并且/或者因为您的同事不感兴趣而在第一时间努力引入源代码控制,那么SVN的简单性和出色的工具(至少在Windows上)就会脱颖而出。

“为什么Git比X好”概述了Git相对于其他scm的各种优缺点。

简要:

Git tracks content rather than files Branches are lightweight and merging is easy, and I mean really easy. It's distributed, basically every repository is a branch. It's much easier to develop concurrently and collaboratively than with Subversion, in my opinion. It also makes offline development possible. It doesn't impose any workflow, as seen on the above linked website, there are many workflows possible with Git. A Subversion-style workflow is easily mimicked. Git repositories are much smaller in file size than Subversion repositories. There's only one ".git" directory, as opposed to dozens of ".svn" repositories (note Subversion 1.7 and higher now uses a single directory like Git.) The staging area is awesome, it allows you to see the changes you will commit, commit partial changes and do various other stuff. Stashing is invaluable when you do "chaotic" development, or simply want to fix a bug while you're still working on something else (on a different branch). You can rewrite history, which is great for preparing patch sets and fixing your mistakes (before you publish the commits) … and a lot more.

有一些缺点:

There aren't many good GUIs for it yet. It's new and Subversion has been around for a lot longer, so this is natural as there are a few interfaces in development. Some good ones include TortoiseGit and GitHub for Mac. Partial checkouts/clones of repositories are not possible at the moment (I read that it's in development). However, there is submodule support. Git 1.7+ supports sparse checkouts. It might be harder to learn, even though I did not find this to be the case (about a year ago). Git has recently improved its interface and is quite user friendly.

在最简单的用法中,Subversion和Git是差不多的。两者之间没有太大区别:

svn checkout svn://foo.com/bar bar
cd bar
# edit
svn commit -m "foo"

and

git clone git@github.com:foo/bar.git
cd bar
# edit
git commit -a -m "foo"
git push

Git真正的亮点在于分支和与其他人一起工作。

谷歌技术讲座:Linus Torvalds谈git

http://www.youtube.com/watch?v=4XpnKHJAok8

Git Wiki的比较页面

http://git.or.cz/gitwiki/GitSvnComparsion

SubVersion最让我恼火的一点是它把自己的文件夹放在项目的每个目录中,而git只把一个文件夹放在根目录中。这不是什么大事,但这样的小事积少成多。

当然,SubVersion有Tortoise,它(通常)非常好。