What is a version control system? How is Git useful?

后端 未结 4 1102
忘掉有多难
忘掉有多难 2020-12-12 03:21

like for example i am doing ruby on rails and using git for version control.

4条回答
  •  青春惊慌失措
    2020-12-12 03:51

    Version control systems allow you more easily track changes to files ... so say you edit a file and commit it to the system a couple of times in a week ... if something breaks, you can go in and see all the specific line by line changes you made to that file over time, until you find the change that caused the problem ... much harder if you're saving different copies of your file right? (This feature is so awesome that I know authors who use it to track changes to books that they are writing!)

    Where it really shines, though, is a situation where different developers are working on a particular file at the same time ... so if I edit lines 1- 20 of a 400 line code file, and you edit 97 - 143, the version control system can merge those changes together so that when you go to do an update, you get my changes merged into your file and can see how my code affects what you've written if any.

    Even better, if we've worked on the same lines of code the version control system will try to merge those changes, and if it doesn't it will warn you of the conflict ... then you can get with the other developer and figure out how to merge your changes manually. Of course with version control you're usually working on a bigger piece of software, so you can also pull in updates to other files that you aren't working on directly either.

    With git, you get one other really killer feature that makes developers swoon ...

    Say you are working on your code, diligently trying to add a feature to your software, bu you get an emergency call, 'PLEASE FIX XYZ, THE SITE IS NOT WORKING!"

    Without version control, you'd have to go comment out all the stuff you just added, then try to fix the problem, and if you forgot something somewhere, it might cause even more problems as you try to hunt down the new bug that you introduced because you didn't remember all the new code you wrote (can you tell I've been there before?) ... with Git, you can simply 'branch' (create a different kinda virtual copy of your code) ... and work on your new feature ... then when that 3am call comes in, you can just switch back to the main stable branch of the software, commit the fix, push it live ... then go back to working on your feature.
    very fricking nice right?

    There are lots of other things you get with version control systems (specifically git) for free, (built in ability to compare version of the same file, localized copy of the entire code base with git, ability to change commit messages and history etc etc).

    I'd recommend the free Git community book to help you along
    https://github.com/rails/jquery-ujs
    Hope this helps

提交回复
热议问题