当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Confused with the concept of GIT Repositories

问题描述:

I went for an interview where they asked me whether I use GIT-REPOSITORIES to merge my projects. For which I was quite.

I looked Wikipedia and Other stuff on net for this but didn't find anything that can force me to go for it.

Please tell me what exactly is GIT-REPOSITORIES and how is it useful. Is it beneficial for me as I am totally confused by all that stuff on the internet ?

Currently, I create projects in PHP by dividing them into smaller independent modules and then merge them all by myself.

网友答案:

Git is just one of several types of source control software.

At my day job, we use Mercurial, which is a DVCS (Distributed version control system).

Imagine you're working on a website and you've got a remote server. I guess right now you're downloading files via FTP, editing them, and uploading them. Do you take backups incase it goes wrong? What if you mix up backups, or you're not sure which change made the error? Then I guess you've got to manually re-upload each of these files into the right places, which will likely break the website for a period of time as files are out of sync.

Also imagine you're working on a codebase that's also being worked on by colleagues. Dave tells you he's just finished all that work on db-abstract.php, but then you get a sinking feeling, as you've just changed a load of code in db-abstract.php too.

With source control, when you make changes to files, you commit the changes, and the changes you've made are all recorded. It's recorded what lines of code you've added, and what you've removed.

When you've finished your work you can "push" them to a central repository where others can "pull" your changes. If you and Dave realise you've worked on the same file, you'll get a merge conflict. You'll then be shown a two sided screen where the changes Dave made, and the changes you made are compared. It'll try to merge them automatically, but if it can't, it'll ask for your help. You can then clearly see which bits of code have been added, changed and why. You'll merge the files together, then commit that change.

Eventually you end up with a whole load of changes that add a brand new feature to a system across possibly hundreds of files, these will all be grouped together into a branch, which describes the feature. All you have to do to make those changes live is push them to the live server, and on the live server, update it's working directory to this branch, or merge the branch into it's default branch. All the changes will instantly be live. If anything went wrong on the live server, or from user testing, you can simply "rollback" which will instantly revert all those changed files to their previous versions.

Once you've worked with source control you'll never go back and you simply cannot work on large code bases collaboratively with other devs without it.

网友答案:

If you work alone, you shouldn't bother with git. Git in general is a version control system which allows you to "jump" back to any point of development. Also its extremely useful if you work in a team - everyone has his own "branch" where he develops new functions, designs or something else, and later you can merge every branch into the "master" branch.

Git has a lot of functions which i cant cover here - because i dont even know all myself.^^ More infos can be retrieved on the official page:

http://git-scm.com/

分享给朋友:
您可能感兴趣的文章:
随机阅读: