Why should I use version control?

2019-01-04 16:10发布

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."

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.

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.

19条回答
冷血范
2楼-- · 2019-01-04 16:43

Something that no one else seems to have explicitly mentioned is the tagging or labeling of releases. If you have a client using version 1 of your software and you're busy working on version 2 what do you do when the client reports a bug and you need to build version 1.1?

A source control system will let you label every release you make so you can go back to it later, make the fix (and merge that fix into the new version 2 code) and make a new release without worrying that you might accidentally deliver something that isn't ready.

Source control is a core part of modern software development. If you're not using it (even for personal projects as the more experience you have the better) you're doing something wrong.

Usually one of the first questions I ask when being interviewed for a job is "What do you use for source control?" So far only one place has said "Nothing" but they were planning to fix that "Real soon now..."

查看更多
叼着烟拽天下
3楼-- · 2019-01-04 16:48

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.

查看更多
霸刀☆藐视天下
4楼-- · 2019-01-04 16:49

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.

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.


Original author: Bill Karwin

查看更多
何必那么认真
5楼-- · 2019-01-04 16:49

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.

查看更多
Evening l夕情丶
6楼-- · 2019-01-04 16:50

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.

查看更多
祖国的老花朵
7楼-- · 2019-01-04 16:52

Sounds like you're looking for something a bit more light-weight. Check out Mercurial (awesome reference book). I use it for everything, from source code to personal correspondence.

Some benefits:

  • Giant Undo button, so you can return the those halcyon days of last week when the code actually ran
  • Throw-away code. Not sure if this is the best way to do something? Make a branch and experiment. Nobody but you ever has to know about it if you're using a DVCS like mercurial.
  • Syncronized development. I develop on 4 different computers. I push and pull between them to keep the current, so no matter which one I'm at I've got the newest versions.
查看更多
登录 后发表回答