简体   繁体   English

什么是版本控制系统? Git有什么用?

[英]What is a version control system? How is Git useful?

例如,例如,我在Rails上执行ruby,并使用git进行版本控制。

I use git as a sole developer an I could not imagine life without it. 我将git用作唯一的开发人员,没有它我无法想象生活。 With git, I always know what I am doing and what I have modified. 使用git时,我总是知道我在做什么以及已经修改了什么。 I can make experimental changes without fear of not remembering what I changed. 我可以进行实验性更改,而不必担心忘记自己所做的更改。 I can look at old versions of files in case I deleted something that now I want back. 我可以查看旧版本的文件,以防万一我删除了现在想要恢复的文件。

I can always go to my terminal and type git status and see what files I have changed. 我总是可以在终端上输入git status ,查看我更改了哪些文件。 I can type git diff to see those changes. 我可以输入git diff来查看这些更改。 If I decide my changes are no good an I want to go back to where I was I just type git checkout . 如果我认为所做的更改不好,我想回到我原来的位置,只需键入git checkout . .

The best part about Git is unlike other source control systems, Git can work offline. 与其他源代码控制系统不同,关于Git的最好的部分是Git可以脱机工作。 Doesn't matter whether you are on a plane or at home or some distant place with no connectivity. 不管是在飞机上还是在家里还是在没有连接的遥远地方。 You can still commit changes to your local git repository & push it to centralized server (if you have one) when you are connected. 连接后,您仍然可以将更改提交到本地git存储库,并将其推送到集中式服务器(如果有)。 One more thing which makes Git very powerful is 'Branches'. 使Git非常强大的另一件事是“分支”。 If you want to do a bug fix or want to try something new without harming your current working code, just create a branch & work on it. 如果您想进行错误修复或在不损害当前工作代码的情况下尝试新的东西,只需创建一个分支并对其进行处理。 When things ae working fine in your branch, you can merge it to the master branch. 当分支中的一切正常时,您可以将其合并到master分支中。

I would say Git provides more flexibility than anything other SCM. 我想说Git提供了比其他任何SCM更大的灵活性。

Version control systems really shine when you're working with another person, or thousands of people; 当您与另一个人或成千上万的人一起工作时,版本控制系统才真正发挥作用。 as people work on files, chances are good they'll work in similar spaces. 人们在处理文件时,很有可能会在相似的空间工作。 Source code control systems let you merge changes from multiple developers into one coherent product, roll back mistakes, figure out who wrote which specific lines of code (to ask them why their code doesn't work two months later), provide excellent business continuity, etc. 使用源代码控制系统,您可以多个开发人员的更改合并到一个一致的产品中,回退错误,找出谁编写了哪些特定的代码行(问他们为什么两个月后他们的代码不起作用),提供了出色的业务连续性,等等

But they are still wonderful with just one developer: check in comments about why you did something in some particular fashion can be worth their weight in gold six months later. 但是,仅用一个开发人员,它们仍然很棒:请检查一下为什么您以某种特定方式进行操作的评论在六个月后值得他们投入金牌。 You can checkin large changes that depend upon four separate files all at once, and then, if you need to undo it, one single command will back out the changes on all four files at once. 您可以一次检入依赖于四个单独文件的大型更改,然后,如果需要撤消它,一个命令将同时撤消所有四个文件的更改。

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. 凡真正的亮点,不过,在这里不同的开发人员在同一时间的特定文件的工作情况...所以,如果我编辑400行代码文件的行1-20,和编辑97 - 143,版本控制系统可以将这些更改合并在一起,以便您进行更新时,将我的更改合并到文件中,并可以查看我的代码如何影响您编写的内容。

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 ... 有了git,您将获得另一个真正的杀手级功能,这使开发人员不知所措...

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!" 假设您正在编写代码,努力尝试向软件中添加功能,但如果您接到紧急电话,“请修复XYZ,该网站无法正常工作!”

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. 没有版本控制,您将不得不注释掉刚添加的所有内容,然后尝试解决问题,如果您忘记了某个地方的内容,则在尝试查找新的错误时可能会导致更多的问题。引入是因为您不记得自己编写的所有新代码(可以告诉我以前去过那里吗?)...使用Git,您可以简单地“分支”(创建代码的另一种虚拟副本)。 。并继续使用您的新功能...然后,当凌晨3点打来电话时,您可以切换回软件的主要稳定分支,提交修订,将其实时推送...然后再使用您的功能。
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). 版本控制系统(特别是git)是免费提供的许多其他功能,(内置的功能可以比较同一文件的版本,具有git的整个代码库的本地化副本,可以更改提交消息和历史记录等) )。

I'd recommend the free Git community book to help you along 我会推荐免费的Git社区书来帮助您
https://github.com/rails/jquery-ujs https://github.com/rails/jquery-ujs
Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Ruby on Rails中的Git版本控制系统中进行SASS文件管理 - SASS files management in Git version control system in Ruby on Rails 如何完全忽略目前我使用git在版本控制下跟踪的目录? - How to completely ignore directories that until now I was tracking under version control using git? 如何将文本合并在一起? 像版本控制系统一样? - How does one merge texts together? like a version control system would? Rails的版本控制和部署工作流程是什么? - What is your version control and deployment workflow with Rails? 排除使用Capistrano部署文件,同时仍然使用Git进行版本控制 - Excluding files from being deployed with Capistrano while still under version control with Git 有哪些常用和有用的技术可以优化数据库性能? - What are the common and useful techniques to optimize database performance? Rails开发有哪些有用的Emacs功能 - What are useful Emacs features for Rails development 对“ rvm需求”给出的依赖性有什么用? - What are the dependencies given on “rvm requirements” useful for? Rails 3 app,如何获得GIT版本和更新网站? - Rails 3 app, How to get GIT version and update website? 适用于CMS的MySQL / Rails版本控制-通常如何进行? - MySQL/Rails Version Control for CMS - How is it usually done?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM