324

我正在开始一个新的分布式项目。我应该使用 SVN 还是 Git,为什么?

4

21 回答 21

255

SVN is one repo and lots of clients. Git is a repo with lots of client repos, each with a user. It's decentralised to a point where people can track their own edits locally without having to push things to an external server.

SVN is designed to be more central where Git is based on each user having their own Git repo and those repos push changes back up into a central one. For that reason, Git gives individuals better local version control.

Meanwhile you have the choice between TortoiseGit, GitExtensions (and if you host your "central" git-repository on github, their own client – GitHub for Windows).

If you're looking on getting out of SVN, you might want to evaluate Bazaar for a bit. It's one of the next generation of version control systems that have this distributed element. It isn't POSIX dependant like git so there are native Windows builds and it has some powerful open source brands backing it.

But you might not even need these sorts of features yet. Have a look at the features, advantages and disadvantages of the distributed VCSes. If you need more than SVN offers, consider one. If you don't, you might want to stick with SVN's (currently) superior desktop integration.

于 2008-10-02T09:55:52.523 回答
112

我从来没有理解过“git 在 Windows 上不好”的概念;我专门在 Windows 下开发,我从来没有遇到过 git 的任何问题。

我肯定会推荐 git 而不是颠覆;它只是更加通用,并允许以颠覆从未真正做到的方式“离线开发”。它可以在几乎所有可以想象的平台上使用,并且具有比您可能使用的更多的功能。

于 2008-10-02T10:17:26.497 回答
76

这是我对一些重复问题的答案的副本,此后我删除了关于 Git 与 SVN(2009 年 9 月)的问题。

更好的?除了通常的链接WhyGitIsBetterThanX 之外,它们是不同的:

一个是基于分支和标签的廉价副本的中央 VCS,另一个 (Git) 是基于修订图的分布式 VCS。另请参见VCS 的核心概念


第一部分产生了一些错误的评论,假装这两个程序(SVN 和 Git)的基本目的是相同的,但它们的实现方式却截然不同。
为了阐明SVN 和 Git 之间的根本区别,让我改写一下:

  • SVN 是修订控制的第三个实现:RCS,然后是 CVS,最后是 SVN管理版本化数据的目录。SVN 提供 VCS 功能(标签和合并),但它的标签只是一个目录副本(就像一个分支,除了你不“应该”接触标签目录中的任何东西),它的合并仍然很复杂,目前基于 meta -添加数据以记住已经合并的内容。

  • Git 是一个文件内容管理(一种用于合并文件的工具),演变成一个真正的版本控制系统,基于提交的 DAG(有向无环图),其中分支是数据历史的一部分(而不是数据本身),并且标签是真正的元数据。

要说它们没有“根本上”不同,因为您可以实现相同的目标,解决相同的问题,这是……在很多层面上都是错误的。

  • 如果您有许多复杂的合并,使用 SVN 执行它们会更长且更容易出错。如果您必须创建许多分支,则需要管理和合并它们,使用 Git 比使用 SVN 更容易,尤其是在涉及大量文件的情况下(速度变得很重要)
  • 如果您对正在进行的工作进行了部分合并,您将利用 Git 暂存区域(索引)仅提交您需要的内容,存储其余部分,然后继续另一个分支。
  • 如果您需要离线开发......那么使用 Git,您始终“在线”,拥有自己的本地存储库,无论您想与其他存储库遵循什么工作流程。

仍然对那个旧(已删除)答案的评论坚持:

VonC:您将实现的根本差异(差异非常根本,我们都明确同意这一点)与目的差异混淆了。
它们都是用于相同目的的工具:这就是为什么许多以前使用 SVN 的团队能够非常成功地将其转储为 Git。
如果他们没有解决同样的问题,这种替代性就不会存在。

,我回复说:

“可替代性”...有趣的术语(用于计算机编程)。
当然,Git 几乎不是 SVN 的子类型。

您可以使用两者实现相同的技术特性(标记、分支、合并),但 Git 不会妨碍您,让您可以专注于文件的内容,而无需考虑工具本身。

您当然不能(总是)只用 Git 替换 SVN,“而不改变该程序的任何理想属性(正确性,执行的任务,......)”(这是对上述可替换性定义的引用):

  • 一个是扩展的修订工具,另一个是真正的版本控制系统。
  • 一种适用于具有简单合并工作流程和(不是太多)并行版本的中小型单体项目。SVN 就足够了,你可能不需要所有的 Git 功能。
  • 另一个允许基于多个组件的大中型项目(每个组件一个 repo),在复杂的合并工作流中在多个分支之间合并大量文件,分支中的并行版本,改造合并等等。您可以使用 SVN 来做到这一点,但使用 Git 会更好。
    SVN 根本无法通过任何合并工作流程管理任何规模的项目。吉特可以。

同样,它们的性质是根本不同的(这会导致不同的实现,但这不是重点)。
一种将修订控制视为目录和文件,另一种仅看到文件的内容(以至于空目录甚至不会在 Git 中注册!)。

一般的最终目标可能是相同的,但您不能以相同的方式使用它们,也不能解决同一类问题(范围或复杂性)。

于 2010-03-30T22:17:27.167 回答
37

SVN 的 2 个很少被提及的主要优势:

  1. 大文件支持。除了代码,我还使用 SVN 来管理我的主目录。SVN 是唯一一个不会阻塞我的 TrueCrypt 文件的 VCS(无论是否分发)(如果有另一个 VCS 可以有效处理 500MB 以上的文件,请纠正我)。这是因为差异比较是流式传输的(这是非常重要的一点)。Rsync 是不可接受的,因为它不是 2-way。

  2. 部分存储库(子目录)签出/签入。Mercurial 和 bzr 不支持这个,git 的支持是有限的。这在团队环境中很糟糕,但如果我想从我的家庭目录中检查另一台计算机上的某些内容,这是非常宝贵的。

只是我的经历。

于 2009-08-11T16:26:36.433 回答
25

在进行更多研究并查看此链接后:https ://git.wiki.kernel.org/articles/g/i/t/GitSvnComparison_cb82.html

(以下部分摘录):

  • 它非常快。我用过的其他 SCM 都无法跟上它,而且我用过很多,包括 Subversion、Perforce、darcs、BitKeeper、ClearCase 和 CVS。
  • 它是完全分布式的。存储库所有者无法指定我的工作方式。我可以在笔记本电脑上断开连接时创建分支并提交更改,然后将其与任意数量的其他存储库同步。
  • 同步可以发生在许多媒体上。SSH 通道,通过 HTTP 通过 WebDAV、通过 FTP 或通过发送包含要由消息接收者应用的补丁的电子邮件。中央存储库不是必需的,但可以使用。
  • 分支甚至比它们在 Subversion 中的便宜。创建一个分支就像将一个 41 字节的文件写入磁盘一样简单。删除一个分支就像删除那个文件一样简单。
  • 与 Subversion 分支不同的是,它们带有完整的历史记录。无需执行奇怪的副本并遍历副本。使用 Subversion 时,我总是发现查看分支上文件在创建分支之前发生的历史记录很尴尬。来自#git:spearce:我不了解页面中有关SVN的一件事。我在 SVN 上创建了一个分支并浏览历史记录显示了整个历史记录在分支中的一个文件
  • Git 中的分支合并更简单、更自动化。在 Subversion 中,您需要记住上次合并的修订版本,以便生成正确的合并命令。Git 会自动执行此操作,并且始终正确执行。这意味着将两个分支合并在一起时出错的可能性较小。
  • 分支合并被记录为存储库正确历史的一部分。如果我将两个分支合并在一起,或者如果我将一个分支合并回它来自的主干,则该合并操作将作为我执行的存储库历史记录的一部分以及何时执行。当合并就在日志中时,很难争论谁执行了合并。
  • 创建存储库是一个简单的操作: mkdir foo; 光盘富; git init 就是这样。这意味着我现在为所有东西创建了一个 Git 存储库。我倾向于每个班级使用一个存储库。大多数这些存储库的磁盘空间都在 1 MB 以下,因为它们只存储讲义、家庭作业和我的 LaTeX 答案。
  • 存储库的内部文件格式非常简单。这意味着修复非常容易,但更好的是,因为它非常简单,很难被损坏。我认为没有人曾经有过 Git 存储库被损坏的情况。我已经看到带有 fsfs 的 Subversion 本身会损坏。而且我已经看到 Berkley DB 自我损坏太多次,以至于无法将我的代码信任到 Subversion 的 bdb 后端。
  • Git 的文件格式非常擅长压缩数据,尽管它是一种非常简单的格式。Mozilla 项目的 CVS 存储库大约 3 GB;Subversion 的 fsfs 格式大约为 12 GB。在 Git 中它大约是 300 MB。

在阅读了所有这些之后,我确信 Git 是正确的选择(尽管存在一点学习曲线)。我也在 Windows 平台上使用过 Git 和 SVN。

我很想听听其他人在阅读以上内容后要说什么?

于 2010-11-13T09:26:48.030 回答
12

I would set up a Subversion repository. By doing it this way, individual developers can choose whether to use Subversion clients or Git clients (with git-svn). Using git-svn doesn't give you all the benefits of a full Git solution, but it does give individual developers a great deal of control over their own workflow.

I believe it will be a relatively short time before Git works just as well on Windows as it does on Unix and Mac OS X (since you asked).

Subversion has excellent tools for Windows, such as TortoiseSVN for Explorer integration and AnkhSVN for Visual Studio integration.

于 2008-10-02T10:05:16.997 回答
11

有趣的是:我在 Subversion Repos 中托管项目,但通过 Git Clone 命令访问它们。

请阅读在 Google 代码项目中使用 Git 进行开发

尽管 Google Code 原生使用 Subversion,但您可以在开发过程中轻松使用 Git。搜索“git svn”表明这种做法很普遍,我们也鼓励您尝试一下。

在 Svn 存储库上使用 Git 给我带来了好处:

  1. 我可以在多台机器上进行分布式工作,向它们提交和拉取
  2. 我有一个中央 backup/publicsvn 存储库供其他人查看
  3. 他们可以自由地为自己使用 Git
于 2008-10-02T13:04:55.893 回答
9

没有真正回答你的问题,但如果你想要分布式修订控制的好处- 听起来像你 - 并且你正在使用 Windows,我认为你最好使用Mercurial而不是 Git 作为 Mercurial 有更好的 Windows 支持。Mercurial 也有 Mac 端口。

于 2008-10-02T10:34:55.207 回答
9

如果您的团队已经熟悉 cvs 或 svn 等版本和源代码控制软件,那么对于一个简单且小型的项目(如您声称的那样),我建议您坚持使用 SVN。我对 svn 真的很满意,但是对于我在 django 上做的当前电子商务项目,我决定使用 git(我在 svn 模式下使用 git,即使用我推送和拉取的集中式 repo为了与至少一位其他开发人员合作)。另一位开发人员对 SVN 很满意,虽然其他人的经验可能不同,但我们俩都在为这个小项目拥抱 git 时遇到了非常糟糕的时光。(我们都是 Linux 的铁杆用户,如果这很重要的话。)

当然,您的里程可能会有所不同。

于 2008-10-02T11:32:56.067 回答
8

The main point is, that Git is a distributed VCS and Subversion a centralized one. Distributed VCSs are a little bit more difficult to understand, but have many advantages. If you don't need this advantages, Subversion may the better choice.

Another question is tool-support. Which VCS is better supported by the tools you plan to use?

EDIT: Three years ago I answered this way:

And Git works on Windows at the moment only via Cygwin or MSYS. Subversion supported Windows from the beginning. As the git-solutions for windows may work for you, there may be problems, as the most developers of Git work with Linux and didn't have portability in the mind from the beginning. At the moment I would prefer Subversion for development under Windows. In a few years this may be irrelevant.

Now the world has changed a little bit. Git has a good implementation on windows now. Although I tested not thouroughly on windows (as I no longer use this system), I'm quite confident, that all the major VCS (SVN, Git, Mercurial, Bazaar) have proper Windows-implementation now. This advantage for SVN is gone. The other points (Centralized vs. Distributed and the check for tool support) stay valid.

于 2008-10-02T09:55:25.257 回答
7

Definitely svn, since Windows is—at best—a second-class citizen in the world of git (see http://en.wikipedia.org/wiki/Git_(software)#Portability for more details).

UPDATE: Sorry for the broken link, but I've given up trying to get SO to work with URIs that contain parentheses. [link fixed now. -ed]

于 2008-10-02T09:52:42.797 回答
6

I would opt for SVN since it is more widely spread and better known.

I guess, Git would be better for Linux user.

于 2008-10-02T09:49:16.237 回答
4

归结为:

你的发展会是线性的吗?如果是这样,你应该坚持使用 Subversion。

另一方面,如果您的开发不是线性的,这意味着您需要为不同的更改创建分支,然后将这些更改合并回主开发线(Git 称为主分支),那么 Git 会做给你更多。

于 2011-01-21T14:42:50.580 回答
4

Git is not natively supported under Windows, just yet. It is optimized for Posix systems. However running Cygwin or MinGW lets you run Git successful.

Nowadays I prefer Git over SVN, but it takes a while to get over the threshold if you come from CVS, SVN land.

于 2008-10-02T09:52:31.427 回答
4

I would probably choose Git because I feel it's much more powerful than SVN. There are cheap Code Hosting services available which work just great for me - you don't have to do backups or any maintenance work - GitHub is the most obvious candidate.

That said, I don't know anything regarding the integration of Visual Studio and the different SCM systems. I imagine the integration with SVN to notably better.

于 2008-10-02T09:53:47.227 回答
4

我用SVN很久了,但是每次用Git的时候,都觉得Git强大很多,轻量级,虽然有点学习曲线但是比SVN好。

我注意到的是,每个 SVN 项目随着它的增长,都会变成一个非常大的项目,除非它被导出。其中,GIT 项目(连同 Git 数据)的重量非常轻。

在 SVN 中,我与从新手到专家的开发人员打过交道,新手和中级如果从另一个 SVN 项目复制一个文件夹以重用它,似乎会引入文件冲突。然而,我认为在 Git 中,您只需复制文件夹即可,因为 Git 不会在其所有子文件夹中引入 .git 文件夹(就像 SVN 那样)。

在与 SVN 打交道很久之后,我终于考虑将我和我的开发人员转移到 Git,因为它很容易协作和合并工作,还有一个很大的优势是可以提交本地副本的更改。需要,然后最后一口气推送到服务器上的分支,这与 SVN 不同(我们必须不时在服务器上的存储库中提交更改)。

谁能帮我决定我是否真的应该使用 Git?

于 2010-11-13T09:12:17.050 回答
3

May I expand on the question and ask if Git work well on MacOS?

Reply to Comments: Thanks for the news, I'd been looking forward to trying it out. I'll install it at home on my Mac.

于 2008-10-02T09:55:41.260 回答
3

have you tried Bzr?

It's pretty good, connonical (the people who make Ubuntu) made it because they didn't like anything else on the market...

于 2008-10-02T10:07:05.227 回答
3

YouTube 上有一个关于此的有趣视频。它来自 Linus Torwalds 本人:Goolge 技术讲座:Linus Torvalds on git

于 2008-10-02T11:23:12.470 回答
2

SVN seems like a good choice under Windows, as pointed by other people.

If some of your developper wants to try GIT, it may always use GIT-SVN where the SVN repository is recreated in a GIT repository. Then he should be able to work locally with GIT and then use SVN to publish its changes to the main repository.

于 2008-10-02T10:06:17.133 回答
1

您必须使用 DVCS,这就像源管理方面的巨大飞跃。就我个人而言,我使用Monotone,它加快了开发时间。我们在 Windows、Linux 和 Mac 上使用它,它非常稳定。我什至让 buildbot 在每个平台上进行项目的夜间构建。

分布式 DVCS 通常意味着您将创建一个中央服务器,供人们推送更改。

于 2008-10-02T10:32:38.660 回答