How does source control work




















The main concept of a centralized system is that it works in a client and server relationship. The repository is located in one place and provides access to many clients. All changes, users, commits and information must be sent and received from this central repository. Distributed systems are a newer option.

In distributed version control, each user has their own copy of the entire repository, not just the files but the history as well. Think of it as a network of individual repositories. In many cases, even though the model is distributed, services like Beanstalk are used for simplifying the technical challenges of sharing changes. The two most popular distributed version control systems are Git and Mercurial.

Which one is right for you? This really depends on how you work. We usually recommend Subversion if you are just getting started, are not comfortable with the command line or do not plan to do a lot of branching and merging. Otherwise, we encourage you to try Git or Mercurial and see if you like it. Why is version control important? If this sounds familiar: Communicated with your team via email about updates.

Made updates directly on your production server. Accidentally overwrote some files, which can never be retrieved again. You can now look forward to this instead: File names and directory structures that are consistent for all team members.

Making changes with confidence, and even reverting when needed. Relying on source control as the communication medium for your team. Easily deploying different versions of your code to staging or production servers. Understanding who made a change and when it happened. The basic concepts Tracking changes A version control system is mostly based around one concept, tracking changes that happen within directories or files. Committing As you work with your files that are under version control, each change is tracked automatically.

Revisions and Changesets When a commit is made, the changes are recorded as a changeset and given a unique revision. See the diagram at the right. In the simplest case, the database contains a linear history: each change is made after the previous one.

In that case, the version history splits and then merges again. The picture below gives examples. There are two general varieties of version control: centralized and distributed. Distributed version control is more modern, runs faster, is less prone to errors, has more features, and is somewhat more complex to understand.

You will need to decide whether the extra complexity is worthwhile for you. Some popular version control systems are Git distributed , Mercurial distributed , and Subversion centralized. The main difference between centralized and distributed version control is the number of repositories. In centralized version control, there is just one repository, and in distributed version control, there are multiple repositories.

Here are pictures of the typical arrangements:. In centralized version control , each user gets his or her own working copy, but there is just one central repository. As soon as you commit, it is possible for your co-workers to update and to see your changes.

For others to see your changes, 2 things must happen:. In distributed version control , each user gets his or her own repository and working copy.

After you commit, others have no access to your changes until you push your changes to the central repository. When you update, you do not get others' changes unless you have first pulled those changes into your repository. For others to see your changes, 4 things must happen:. Notice that the commit and update commands only move changes between the working copy and the local repository, without affecting any other repository.

By contrast, the push and pull commands move changes between the local repository and the central repository, without affecting your working copy. It is sometimes convenient to perform both pull and update , to get all the latest changes from the central repository into your working copy. The hg fetch and git pull commands do both pull and update. In other words, git pull does not follow the description above, and git push and git pull commands are not symmetric.

A version control system lets multiple users simultaneously edit their own copies of a project. Usually, the version control system is able to merge simultaneous changes by two different users: for each line, the final version is the original version if neither user edited it, or is the edited version if one of the users edited it.

A conflict occurs when two different users make simultaneous, different changes to the same line of a file. In this case, the version control system cannot automatically decide which of the two edits to use or a combination of them, or neither!

Manual intervention is required to resolve the conflict. Change 1 and Change 2 are considered simultaneous if:. In a distributed version control system, there is an explicit operation, called merge , that combines simultaneous edits by two different users. Sometimes merge completes automatically, but if there is a conflict, merge requests help from the user by running a merge tool.

In centralized version control, merging happens implicitly every time you do update. It is better to avoid a conflict than to resolve it later.

The best practices below give ways to avoid conflicts, such as that teammates should frequently share their changes with one another. Conflicts are bound to arise despite your best efforts.

It's smart to practice conflict resolution ahead of time, rather than when you are frazzled by a conflict in a real project. You can do so in this tutorial about Git conflict resolution. Recall that update changes the working copy by applying any edits that appear in the repository but have not yet been applied to the working copy. For the examples in this book, you will use software source code as the files being version controlled, though in reality you can do this with nearly any type of file on a computer.

If you are a graphic or web designer and want to keep every version of an image or layout which you would most certainly want to , a Version Control System VCS is a very wise thing to use. It allows you to revert selected files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

Using a VCS also generally means that if you screw things up or lose files, you can easily recover. In addition, you get all this for very little overhead. This approach is very common because it is so simple, but it is also incredibly error prone.

To deal with this issue, programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control. RCS works by keeping patch sets that is, the differences between files in a special format on disk; it can then re-create what any file looked like at any point in time by adding up all the patches.

Changes made in one part of the software can be incompatible with those made by another developer working at the same time. This problem should be discovered and solved in an orderly manner without blocking the work of the rest of the team. Further, in all software development, any change can introduce new bugs on its own and new software can't be trusted until it's tested.

So testing and development proceed together until a new version is ready. Good version control software supports a developer's preferred workflow without imposing one particular way of working. Ideally it also works on any platform, rather than dictate what operating system or tool chain developers must use.

Great version control systems facilitate a smooth and continuous flow of changes to the code rather than the frustrating and clumsy mechanism of file locking - giving the green light to one developer at the expense of blocking the progress of others.

Software teams that do not use any form of version control often run into problems like not knowing which changes that have been made are available to users or the creation of incompatible changes between two unrelated pieces of work that must then be painstakingly untangled and reworked.

If you're a developer who has never used version control you may have added versions to your files, perhaps with suffixes like "final" or "latest" and then had to later deal with a new final version. Perhaps you've commented out code blocks because you want to disable certain functionality without deleting the code, fearing that there may be a use for it later.

Version control is a way out of these problems. Version control software is an essential part of the every-day of the modern software team's professional practices. Individual software developers who are accustomed to working with a capable version control system in their teams typically recognize the incredible value version control also gives them even on small solo projects.

Once accustomed to the powerful benefits of version control systems, many developers wouldn't consider working without it even for non-software projects. Using version control software is a best practice for high performing software and DevOps teams.

Version control also helps developers move faster and allows software teams to preserve efficiency and agility as the team scales to include more developers. Version Control Systems VCS have seen great improvements over the past few decades and some are better than others.

One of the most popular VCS tools in use today is called Git. Like many of the most popular VCS systems available today, Git is free and open source. Regardless of what they are called, or which system is used, the primary benefits you should expect from version control are as follows. A complete long-term change history of every file.

This means every change made by many individuals over the years.



0コメント

  • 1000 / 1000