git 为什么要使用版本控制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1408450/
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
Why should I use version control?
提问by JasonDavis
I was reading a blog where the writer said this
我正在读一个博客,作者说这个
"Code doesn't exist unless it's checked into a version control system. Use version control for everything you do. Any version control, SVN, Git, even CVS, master it and use it."
“代码不存在,除非它被签入版本控制系统。对你所做的一切使用版本控制。任何版本控制,SVN,Git,甚至 CVS,掌握它并使用它。”
I have never used any sort of version control and I do not find it that great. I have googled it and looked at it before, but I just need it put into children's terms if you will please.
我从来没有使用过任何类型的版本控制,我觉得它不是很好。我以前用谷歌搜索过并看过它,但如果你愿意,我只需要把它放在儿童的条款中。
As I understand it right now, things like SVN are for storing your code online for a group of users or other developers to have access to the same code. Once you update some code, you can submit the new version and the SVN will keep copies of old code as well as the new ones you update.
就我现在的理解,像 SVN 这样的东西用于在线存储您的代码,供一组用户或其他开发人员访问相同的代码。一旦您更新了一些代码,您就可以提交新版本,SVN 将保留旧代码的副本以及您更新的新代码。
Is this the basic idea of it or am I getting it completely wrong?
这是它的基本思想还是我完全错了?
If I am right, then it might not be much use if I:
如果我是对的,那么如果我:
- Do not have other people working on the code.
- Do not plan on letting others have the code.
- 不要让其他人处理代码。
- 不要打算让其他人拥有代码。
回答by si618
Have you ever:
你有没有:
- Made a change to code, realised it was a mistake and wanted to revert back?
- Lost code or had a backup that was too old?
- Had to maintain multiple versions of a product?
- Wanted to see the difference between two (or more) versions of your code?
- Wanted to prove that a particular change broke or fixed a piece of code?
- Wanted to review the history of some code?
- Wanted to submit a change to someone else's code?
- Wanted to share your code, or let other people work on your code?
- Wanted to see how much work is being done, and where, when and by whom?
- Wanted to experiment with a new feature without interfering with working code?
- 对代码进行了更改,意识到这是一个错误并想恢复?
- 丢失代码或备份太旧?
- 必须维护一个产品的多个版本?
- 想查看您的代码的两个(或更多)版本之间的区别吗?
- 想要证明某个特定更改破坏或修复了一段代码?
- 想回顾一些代码的历史吗?
- 想要提交对他人代码的更改?
- 想要分享您的代码,还是让其他人处理您的代码?
- 想知道正在完成多少工作,以及在何处、何时以及由谁完成?
- 想要在不干扰工作代码的情况下试验新功能吗?
In these cases, and no doubt others, a version control system should make your life easier.
在这些情况下,毫无疑问,在其他情况下,版本控制系统应该让您的生活更轻松。
To misquote a friend: A civilised tool for a civilised age.
错误引用朋友的话:文明时代的文明工具。
回答by R. Martinho Fernandes
Even if you work alone you can benefit from source control. Among others, for these reasons:
即使您单独工作,您也可以从源代码控制中受益。除其他外,出于以下原因:
You don't lose anything. I never again commented out code. I simply delete it. It doesn't clutter my screen, and it isn't lost. I can recover it by checking out an old commit.
You can experiment at will. If it doesn't solve the problem, revert it.
You can look at previous versions of the code to find out when and where bugs were introduced.
git bisect
is great in that regard.More "advanced" features like branching and merging let you have multiple parallel lines of development. You can work in two simultaneous features without interference and switch back and forth without much hassle.
You can see "what changed". This may sound basic, but that's something I find myself checking a lot. I very often begin my one-man workflow with: what did I do yesterday?
你不会失去任何东西。我再也没有注释掉代码。我干脆删了。它不会弄乱我的屏幕,也不会丢失。我可以通过检查旧提交来恢复它。
你可以随意尝试。如果它不能解决问题,请将其还原。
您可以查看以前版本的代码以了解错误是在何时何地引入的。
git bisect
在这方面很棒。更多“高级”功能,如分支和合并,让您拥有多条平行的开发线。您可以在没有干扰的情况下同时使用两个功能,并且可以轻松来回切换。
您可以看到“发生了什么变化”。这可能听起来很基本,但这是我发现自己经常检查的东西。我经常开始我的单人工作流程:我昨天做了什么?
Just go ahead and try it. Start slowly with basic features and learn others as you go. You will soon find that you won't ever want to go back to "the dark ages" of no VCS.
请继续尝试。慢慢开始使用基本功能,然后边学边学。您很快就会发现,您再也不想回到没有 VCS 的“黑暗时代”了。
If you want a local VCS you can setup your own subversion server (what I did in the past), but today I would recommend using git
. Much simpler. Simply cd
to your code directory and run:
如果你想要一个本地 VCS,你可以设置你自己的 subversion 服务器(我过去所做的),但今天我建议使用git
. 简单多了。只需cd
到您的代码目录并运行:
git init
Welcome to the club.
欢迎来到俱乐部。
回答by Robert Venables
Version control is a rare tool that I would say is absolutely required, even if you are only using it as a solo developer. Some people say that it's a tool that you live and die by, I agree with that assertion.
版本控制是一种罕见的工具,我会说它是绝对必需的,即使您只是作为单独的开发人员使用它。有人说它是你赖以生存和死亡的工具,我同意这种说法。
You probably use version control right now, even if you don't know it. Do you have any folders that say "XXX Php Code (December)" or "XXX.php.bak.2"? These areforms of version control already. A good version control system will take care of this for you automatically. You will be able to roll back to any point in time (that you have data checked in) and be able to see an exact copy of that data.
您现在可能正在使用版本控制,即使您不知道它。您是否有任何显示“XXX Php 代码(12 月)”或“XXX.php.bak.2”的文件夹?这些已经是版本控制的形式。一个好的版本控制系统会自动为你处理这个问题。您将能够回滚到任何时间点(您已签入数据)并能够看到该数据的精确副本。
Furthermore, if you adopt a system like subversion, and use a remote repository (such as one on a server you own), you will have a place to keep all of your code. Need a copy of your code somewhere else? No problem, just check it out. Hard drive crash at home? Not an issue (at least with your source code).
此外,如果您采用像 subversion 这样的系统,并使用远程存储库(例如您拥有的服务器上的存储库),您将有一个地方可以保存所有代码。需要在其他地方复制您的代码?没问题,检查一下。家里硬盘坏了?不是问题(至少对于您的源代码而言)。
Even if you don't use version control now, you will likely use it at one point in time later in your career and you could benefit from becoming more comfortable with the principles now.
即使您现在不使用版本控制,您也可能会在职业生涯后期的某个时间点使用它,并且您可以从现在对这些原则更加适应中受益。
回答by Ed Schembor
Even working alone, has this ever happened? You run your app, and something does not work and you say "that worked yesterday, and I swear I did not touch that class/method." If you are checking in code regularly, a quick version diff would show exactly what had changed in the last day.
即使独自工作,也有过这种情况吗?你运行你的应用程序,有些东西不起作用,你说“昨天有效,我发誓我没有接触那个类/方法。” 如果您定期检查代码,快速版本差异将准确显示最后一天发生的变化。
回答by Robert Harvey
Here's a scenario that may illustrate the usefulness of source control even if you work alone.
这是一个场景,即使您单独工作,它也可以说明源代码控制的有用性。
Your client asks you to implement an ambitious modification to the website. It'll take you a couple of weeks, and involve edits to many pages. You get to work.
You're 50% done with this task when the client calls and tells you to drop what you're doing to make an urgent but more minor change to the site. You're not done with the larger task, so it's not ready to go live, and the client can't wait for the smaller change. But he also wants the minor change to be merged into your work for the larger change.
Maybe you are working on the large task in a separate folder containing a copy of the website. Now you have to figure out how to do the minor change in a way that can be deployed quickly. You work furiously and get it done. The client calls back with further refinement requests. You do this too and deploy it. All is well.
Now you have to merge it into the work in progress for the major change. What did you change for the urgent work? You were working too fast to keep notes. And you can't just diff the two directories easily now that both have changes relative to the baseline you started from.
您的客户要求您对网站进行雄心勃勃的修改。这将花费您几周的时间,并且涉及对许多页面的编辑。你开始工作。
当客户打来电话并告诉您放弃正在做的事情以对站点进行紧急但更小的更改时,您已完成此任务的 50%。你还没有完成更大的任务,所以它没有准备好上线,客户不能等待较小的变化。但他也希望将较小的更改合并到您的工作中以进行更大的更改。
也许您正在一个包含网站副本的单独文件夹中处理大型任务。现在您必须弄清楚如何以一种可以快速部署的方式进行细微的更改。你拼命工作并完成它。客户端回调进一步细化请求。您也这样做并部署它。一切都很好。
现在您必须将其合并到正在进行的主要更改的工作中。你为紧急工作做了什么改变?你工作太快而无法做笔记。并且您不能简单地区分这两个目录,因为它们都相对于您开始的基线进行了更改。
The above scenario shows that source control can be a great tool, even if you work solo.
上面的场景表明,即使您独自工作,源代码控制也可以是一个很好的工具。
- You can use branches to work on longer-term tasks and then merge the branch back into the main line when it's done.
- You can compare whole sets of files to other branches or to past revisions to see what's different.
- You can track work over time (which is great for reporting and invoicing by the way).
- You can recover any revision of any file based on date or on a milestone that you defined.
- 您可以使用分支来处理长期任务,然后在完成后将分支合并回主线。
- 您可以将整组文件与其他分支或过去的修订版进行比较,看看有什么不同。
- 您可以随时间跟踪工作(顺便说一下,这非常适合报告和开票)。
- 您可以根据日期或您定义的里程碑恢复任何文件的任何修订。
For solo work, Subversion or Git is recommended. Anyone is free to prefer one or the other, but either is clearly better than not using any version control. Good books are "Pragmatic Version Control using Subversion, 2nd Edition" by Mike Mason or "Pragmatic Version Control Using Git" by Travis Swicegood.
对于单独工作,建议使用 Subversion 或 Git。任何人都可以自由选择其中之一,但显然两者都比不使用任何版本控制要好。好书是Mike Mason 的“ Pragmatic Version Control using Subversion, 2nd Edition”或Travis Swicegood 的“ Pragmatic Version Control Using Git”。
Original author: Bill Karwin
原作者:比尔·卡文
回答by gbc
Even as a single developer source control offers a great benefit. It allows you to store your code's history and revert back to previous versions of your software at any time. This allows you fearless flexibility to experiment because you can always restore to another version of your source code that was working.
即使作为单一的开发人员源代码控制也提供了很大的好处。它允许您存储代码的历史记录并随时恢复到软件的先前版本。这使您可以无所畏惧地灵活地进行实验,因为您始终可以恢复到正在运行的源代码的另一个版本。
It's like having a giant "undo" button all the way back to your first line of code.
这就像有一个巨大的“撤消”按钮一直回到你的第一行代码。
回答by Vincent Ramdhanie
Version control is almost impossible to live without after you start using it. It is indispensible if more than one developers are working on the same code base...but it also quite useful for a single developer.
开始使用版本控制后,几乎不可能没有它。如果多个开发人员在同一个代码库上工作,这是必不可少的……但它对于单个开发人员也非常有用。
It tracks the changes in your code and allows you to roll back to previous versions. It frees you to experiment with the knowledge that if anything breaks you can undo your changes.
它跟踪代码中的更改并允许您回滚到以前的版本。它让您可以自由地体验这样的知识:如果有任何问题,您可以撤消更改。
回答by Vincent Ramdhanie
You gain security (in the sense of having a back-up of your code) and versioning of your code (assuming you get into a habit of committing your changes often). Both are very good things even if nobody else ends up ever working on the code with you...
您获得了安全性(在备份代码的意义上)和代码的版本控制(假设您养成了经常提交更改的习惯)。两者都是非常好的事情,即使没有其他人最终与您一起处理代码......
回答by Peter
Version control is great for checking previous versions, even if you're working alone. For example, if you accidentally delete code or a file you can get it back; or you can compare previous versions to see why a new bug has crept in. It's also good if you're one person working in multiple locations.
版本控制非常适合检查以前的版本,即使您是单独工作也是如此。例如,如果您不小心删除了代码或文件,您可以将其找回;或者您可以比较以前的版本,看看为什么会出现新的错误。如果您是在多个地点工作的一个人,这也很好。
My personal favourite is git.
我个人最喜欢的是 git。
回答by Mads Hansen
There are a number of reasons to use version control, even if you are the only person who will ever touch the code.
使用版本控制的原因有很多,即使您是唯一会接触代码的人。
- Backup- what if your hard-drive crashes? Do you have a copy anywhere?
- Revision history- Do you currently keep copies of code in different folders? Version control gives you the ability to track your changes over time and easily diff different revisions, merge, roll back changes, etc. using tools.
- Branches- the ability to test out some changes, still track what you are doing, and then decide whether or not you want to keep it and merge into the main project or just throw it away.
- 备份- 如果您的硬盘崩溃怎么办?你有任何地方的副本吗?
- 修订历史- 您目前是否将代码副本保存在不同的文件夹中?版本控制使您能够随着时间的推移跟踪更改,并使用工具轻松区分不同的修订、合并、回滚更改等。
- 分支- 能够测试一些更改,仍然跟踪您在做什么,然后决定是否要保留它并合并到主项目中,或者只是将其丢弃。
If you keep your code under version control, then it makes it really easy to see which files you have changed (or have forgotten to add to the baseline).
如果您将代码置于版本控制之下,则可以很容易地查看您更改了哪些文件(或忘记添加到基线中)。