使用 git 后,您对 git 的优缺点是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/343675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are your pros and cons of git after having used it?
提问by Kieveli
I'm using SVN right now, and I've used CVS and VSS in the past. SVN is the current favourite in my books, but I've been hearing a lot about git. Of the people that have used git, what are the pros and cons from your experience?
我现在正在使用 SVN,过去我也使用过 CVS 和 VSS。SVN 是我目前最喜欢的书籍,但我听说了很多关于 git 的内容。在使用过 git 的人中,您的经验有哪些优点和缺点?
采纳答案by Jon Skeet
I don't have a lotof experience with git, but:
我对git没有很多经验,但是:
Pros:
优点:
- It's really quick
- Local commits rock
- Quick to start a new repository (no configuration etc)
- github is easy to use
- 真的很快
- 本地提交摇滚
- 快速启动新存储库(无需配置等)
- github易于使用
(I haven't really "needed" the distributed side of things yet, beyond being able to have a local repository and push to a public one.)
(除了能够拥有本地存储库并推送到公共存储库之外,我还没有真正“需要”事物的分布式方面。)
Cons:
缺点:
- Windows support is still lagging behind, I believe - and you can't just use it from a normal command prompt
- Lack of IDE and Explorer integration
- It took me a while to find a good introductory textalong the lines of the redbean book.
- The fact that "adding" a changed file only adds the contents at that point of time (so it can show up as staged for commit andstill have modifications which require another
git add) took a while to grasp
回答by user43563
Number of Commands
命令数量
While svn and other modern VCS like hg or others are nice and useful tools git is a shop full of machine tools. This accounts as pro and a con at the same time. While svn has 30 commands (according to 'svn help') git ships 130 man pages with more or less each of them describing a single command. One reason for this is that git exposes the lower level functions that most users will ever need as command line tools. But even without those lowlevel commands git ships a lot of very powerful tools and are not found in any other VCS I know (see git-bisect, git-filter-branch, git-cherryor git-resetfor examples). While it is very helpful to have those tools at hand it makes it quite difficult for beginner to understand what command they need and need to know and which not.
虽然 svn 和其他现代 VCS 像 hg 或其他是不错和有用的工具,但 git 是一个充满机器工具的商店。这既是利弊又是利弊。虽然 svn 有 30 个命令(根据 'svn help'),git 提供了 130 个手册页,每个手册页或多或少地描述了一个命令。原因之一是 git 公开了大多数用户将需要作为命令行工具的较低级别的功能。但即使没有那些低级命令,git 也提供了许多非常强大的工具,并且在我知道的任何其他 VCS 中都找不到(请参阅git-bisect、git-filter-branch、git-cherry或git-reset举些例子)。虽然手头有这些工具非常有帮助,但初学者很难理解他们需要和需要知道哪些命令,哪些不需要。
Development Model
发展模式
A similar topic is that git is powerful enough to support very different operation modes. This makes it difficult for beginners as there is not really a "best practice" document as the best practice is not build into git. So you have to decide yourself whether you
一个类似的主题是 git 足够强大,可以支持非常不同的操作模式。这对初学者来说很困难,因为没有真正的“最佳实践”文档,因为最佳实践没有内置到 git 中。所以你必须自己决定你是否
- Just use merges to avoid conflicts with you working dir
- Use private branches that get rebased to upstream HEAD
- Use upstream branches
- that are merged regularly (flying fish)
- merged when finished
- Use a tree of one project maintainer, tree maintainers, sub system maintainers, driver maintainers and contributors with each level pulling the patches from the level below (linux kernel)
- 只需使用合并以避免与您的工作目录发生冲突
- 使用重新基于上游 HEAD 的私有分支
- 使用上游分支
- 定期合并(飞鱼)
- 完成后合并
- 使用由一个项目维护者、树维护者、子系统维护者、驱动维护者和贡献者组成的树,每个级别从下面的级别(Linux 内核)提取补丁
As you have your local repository you can even use a very different operation mode than the project you are working on and just adjust your change sets before pushing/publishing them.
由于您拥有本地存储库,您甚至可以使用与您正在处理的项目截然不同的操作模式,只需在推送/发布更改集之前调整更改集。
Path of the Changes
变革之路
Another thing that also counts as pro and con depending on your view point is that working with git is more complicated than with any centralized VCS and even more complicated most other distributed VCS.
根据您的观点,另一件也算得上是利弊的事情是,使用 git 比使用任何集中式 VCS 更复杂,甚至比大多数其他分布式 VCS 更复杂。
With centralized VCS you normally just do a commit and the changes you made go to the repository. In git the changes can go through a quite large number of steps before they end up at their final destination. Typical steps are (not so common steps in parenthesis):
使用集中式 VCS,您通常只需提交一次,您所做的更改就会转到存储库。在 git 中,更改在到达最终目的地之前可能会经历相当多的步骤。典型的步骤是(括号中不是那么常见的步骤):
- Working dir (editing)
- Index aka staging area (git add)
- Local repository (git commit)
- (Other local branch) (git rebase, git cherry-pick, git merge)
- (sub maintainer's repository) (git push, git pull, mail)
- Upstream repository (git push, git pull, mail)
- 工作目录(编辑)
- 索引又名暂存区 (git add)
- 本地存储库(git commit)
- (其他本地分支) (git rebase, git cherry-pick, git merge)
- (子维护者的存储库)(git push、git pull、mail)
- 上游仓库(git push、git pull、mail)
As you can kind of skip the index there are at least 2 steps involved but typically there are more. This requires a deeper understanding of what you are doing and typing a lot more commands. On the other hand this gives you control over each of these steps. You can
由于您可以跳过索引,因此至少涉及 2 个步骤,但通常还有更多步骤。这需要更深入地了解您正在做什么并键入更多命令。另一方面,这使您可以控制每个步骤。你可以
- decide which junks/lines are going into the commit and which are not
- decide which patches you want in which of your local branches
- decide which of your patches are published
- rework, squash, fix, split, reorder your patches before publishing them
- decide yourself which people you trust and accept patches from
- delegate parts of the project to other maintainer you trust.
- 决定哪些垃圾/线路进入提交,哪些不
- 决定您想要在哪个本地分支中使用哪些补丁
- 决定发布哪些补丁
- 在发布补丁之前返工、压缩、修复、拆分、重新排序
- 自己决定信任哪些人并接受补丁
- 将项目的一部分委托给您信任的其他维护者。
All this power and decisions make it difficult for beginners to get started with git. Once mastered they give an enormous control over the code.
所有这些功能和决定使初学者很难开始使用 git。一旦掌握,他们就会对代码进行巨大的控制。
Write Access
写访问
One major pro for any distributed VCS is that contributors do not require write access to benefit from the VCS. Everyone with read access can just clone the repository, create branches when necessary and begin stacking put patch sets. Working with cvs without write access is a real pain - with git there is not a big different how get get your patches in. This is not only a technical advantage but also saves complicated discussions whether this noobie should really get write access.
任何分布式 VCS 的一个主要优点是,贡献者不需要写访问权限即可从 VCS 中受益。每个具有读取权限的人都可以克隆存储库,在必要时创建分支并开始堆叠放置补丁集。在没有写访问权限的情况下使用 cvs 是一个真正的痛苦 - 使用 git 并没有太大的不同,如何获取补丁。这不仅是一个技术优势,而且还避免了这个 noobie 是否真的应该获得写访问权限的复杂讨论。
回答by Binny V A
Pro:
亲:
- Fast - very fast.
- Creating a new repo is very easy compared to SVN
- The full repo is contained in just one .git folder - it will not add a .SVN folder in every folder of your code(not a big deal, but I like it)
- Branching is easier
- GitHub!
- 快——非常快。
- 与 SVN 相比,创建新的 repo 非常容易
- 完整的 repo 只包含在一个 .git 文件夹中 - 它不会在你的代码的每个文件夹中添加一个 .SVN 文件夹(没什么大不了的,但我喜欢它)
- 分支更容易
- GitHub!
Cons:
缺点:
- Cannot checkout a part of the repository(like just one folder or just one file)
- Does not track empty folders
- Bad Windows support(does not bother me much - I use Linux)
- I still have not found a good GUI tool for Git yet(I use KDESVN for SVN). Not a big issue if you are comfortable with CLI.
- 无法检出存储库的一部分(例如只有一个文件夹或只有一个文件)
- 不跟踪空文件夹
- 糟糕的 Windows 支持(并不太困扰我 - 我使用 Linux)
- 我还没有为 Git 找到一个好的 GUI 工具(我使用 KDESVN 作为 SVN)。如果您对 CLI 感到满意,这不是大问题。
回答by Bombe
A lot of people would deny this but the choice of source code management tool influences the way you work. I used to work a lot with Subversion—until I discovered Git for me. I mostly avoided branching in Subversion. Whenever I could not avoid it I preferred setting up a local mirror (using svk). While branching is easily done in both Subversion and Git, only Git makes merging (and rebasing!) fun, Subversion has always been a royal pain when it came to merging time.
很多人会否认这一点,但源代码管理工具的选择会影响您的工作方式。我曾经经常使用 Subversion,直到我发现了 Git。我主要避免在 Subversion 中分支。每当我无法避免它时,我更喜欢设置本地镜像(使用 svk)。虽然分支在 Subversion 和 Git 中都可以轻松完成,但只有 Git 使合并(和变基!)变得有趣,Subversion 在合并时间方面一直是一个令人头疼的问题。
Second thing that I really like about Git (apart from all the points that have already been mentioned) is the “index”, a staging area that holds your next commit, and the possibility to only add single chunks of a changed file to it.
我真正喜欢 Git 的第二件事(除了已经提到的所有要点)是“索引”,一个保存您下一次提交的暂存区,以及只向其中添加已更改文件的单个块的可能性。
回答by Rad
The Windows support is appalling so I moved to Mercurial, another DVCS that's as good.
Windows 支持令人震惊,所以我转向Mercurial,这是另一个同样出色的 DVCS。
The benefits of DVCS become apparent when you for example have a repository in your server in the office and you're working on site. Being able to commit locally without access to your server office (and this rollback when necessary) is brilliant!
例如,当您在办公室的服务器中有一个存储库并且您在现场工作时,DVCS 的优势就变得显而易见。能够在不访问服务器办公室的情况下在本地提交(以及在必要时进行回滚)非常棒!
回答by Ryan McGeary
回答by user43563
Working with git is very different what working with other versioning systems.
使用 git 与使用其他版本控制系统有很大不同。
Having a local repository is very important. It means that you can use the full power of the versioning system (and this is a lot with git) without disturbing anyone. If there is a controversial issue in your project you can just work on it privately - by creating branches, stacking up patches and polishing them. That way you can come back with an ironed out patch set. But even in "normal operation" it is much better if you can clean up your patches before showing them to the public and in fact debugging is much easier if you have sane patches and not just "end of day" snap shots.
拥有本地存储库非常重要。这意味着您可以在不打扰任何人的情况下使用版本控制系统的全部功能(这对 git 来说很重要)。如果您的项目中存在有争议的问题,您可以私下处理它——通过创建分支、堆叠补丁并完善它们。这样你就可以带着一个经过熨烫的补丁集回来。但即使在“正常操作”中,如果您能在向公众展示补丁之前清理它们会更好,事实上,如果您拥有健全的补丁而不仅仅是“一天结束”的快照,调试会容易得多。
Before I commit a bigger set of patches I typically reorder the patches and squash bugfixes on my new code directly into the patch. So the patches look like I never made any mistake. After that my private branch is rebased on top of HEAD and then pushed. I typically never use a merge as it only clutters the history.
在我提交一组更大的补丁之前,我通常会重新排序补丁并将我的新代码上的错误修正直接压缩到补丁中。所以补丁看起来我从来没有犯过任何错误。之后,我的私人分支重新建立在 HEAD 之上,然后推送。我通常从不使用合并,因为它只会使历史变得混乱。
In short: It allows to keep your history clean.
简而言之:它可以保持您的历史记录干净。
This gives you a very different view on your work. It allows you to see the current state as an addition of single patches that create a history that is not just a log but something that you put there on purpose. Patch sets are the bricks you build your application from - and move to the right place if necessary.
这让你对你的工作有一个非常不同的看法。它允许您将当前状态视为单个补丁的添加,这些补丁创建的历史记录不仅是日志,而且是您有意放置的内容。补丁集是您构建应用程序的基础 - 并在必要时移动到正确的位置。
I would never ever voluntarily go back to any other versioning system I used before git or any versioning system that does not support rebase and local branches and commits.
我永远不会自愿回到我在 git 之前使用的任何其他版本控制系统或任何不支持 rebase 和本地分支和提交的版本控制系统。
回答by Aaron Digulla
Merging is much more simple in git since creating branches is the default, not an extra option. So when you have to merge something, you just commit it and then you merge the two branches (the existing one and the new one which git automatically created for your last checkin).
在 git 中合并要简单得多,因为创建分支是默认的,而不是额外的选项。因此,当您必须合并某些内容时,只需提交它,然后合并两个分支(现有分支和 git 为您上次签入自动创建的新分支)。
Also, when using git, you always have the whole repository with you. You can check in while offline and merge later (since merging is much more simple).
此外,在使用 git 时,您始终随身携带整个存储库。您可以在离线时签入并稍后合并(因为合并要简单得多)。
The drawback is that GIT it almost unusable on an USB drive on Windows. Windows disables caching for these and GIT works with millions of tiny files. Also, IDE support is still lacking. I'm not sure the latter is really an issue. The UI which comes with GIT is pretty nice.
缺点是 GIT 在 Windows 上的 USB 驱动器上几乎无法使用。Windows 禁用缓存,而 GIT 可以处理数百万个小文件。此外,仍然缺乏 IDE 支持。我不确定后者是否真的是一个问题。GIT 自带的 UI 非常漂亮。
Also, I'm not 100% happy that you have to "add" existing files all the time [EDIT] and the enormous amount of features. For a beginner, they are overwhelming and it's often unclear why you would want to use a certain option/command. I mean, CVS comes with, say, 20 commands. GIT comes with 73 and each has lots of options (and that's not counting the plumbing commands ...).
此外,我对您必须一直“添加”现有文件 [编辑] 和大量功能并不感到 100% 高兴。对于初学者来说,它们是压倒性的,通常不清楚为什么要使用某个选项/命令。我的意思是,CVS 有 20 个命令。GIT 有 73 个,每个都有很多选项(这还不包括管道命令......)。
回答by Paul
Other considerations:
其他注意事项:
Pros:
优点:
- Flexible: doesn't enforce one, true workflow
- So fast that version control becomes a minor task
- Lightweight branches, easy merging and staging area allow personalized workflows
- More powerful
- Very compact repos
- 灵活:不强制执行一个真正的工作流程
- 如此之快以至于版本控制成为一项小任务
- 轻量级分支、易于合并和暂存区允许个性化的工作流程
- 更有力
- 非常紧凑的回购
Cons:
缺点:
- No built-in access controls
- Weak tools for binary files. Doesn't compact changes to binary files in repo and storing binary files prevents auto-handling of line endings in Windows.
- May be harder to learn because it is more flexible and more powerful. Doesn't always follow CVS/SVN semantics and isn't organized around files.
- 没有内置的访问控制
- 二进制文件的弱工具。不压缩对 repo 中二进制文件的更改,并且存储二进制文件会阻止自动处理 Windows 中的行尾。
- 可能更难学,因为它更灵活、更强大。并不总是遵循 CVS/SVN 语义,也不是围绕文件组织的。
回答by Clinton
The latest version of Git can work directly in Window' command prompt, which is how I use it. The process is fairly trivial for me now.
最新版本的 Git 可以直接在 Window 的命令提示符下工作,我就是这样使用的。这个过程现在对我来说相当简单。
I also have Git installed on an external hard drive and on my jumpdrive. Whenever at a new computer, I run a script that temporarily sets the path to include Git's tools. Then you can continue developing!
我还在外部硬盘驱动器和我的 jumpdrive 上安装了 Git。每当在一台新计算机上时,我都会运行一个脚本来临时设置路径以包含 Git 的工具。然后就可以继续开发了!

