Git (1): git and Version Control Introduction

Source: Internet
Author: User

Tag: git

Intro What is a version control system? Version Control System (VCS)It helps us record and track changes to the content of each file in the project. It can help us save the versions of the project and modify the reasons. We can use this tool to return to a previous state of the project. In addition, the version control system is also a powerful tool for collaborative development. What is git? Is git Distributed version control system (DVCs). Compared with traditional centralized version control systems (such as CVS, subversion, and clearcase), git has the following advantages:
  • Distributed architecture: Network disconnection is not restricted.
  • Branch and merge operations are easy: Creating branches is simple, economical, and fast, which is different from other version control systems. Git combines all the modifications on the branch back to the parent branch, even if multiple times, it is just a blink of an eye
  • Interaction with subversion: git can import all the history from the version library of subversion, and send your changes in Git back to the version library of subversion.

Version Library Version Library (repository)Is where the version control system stores all historical data. Most version control systems store the current status of each file, the historical modification time, Who modified the file, the reason for the modification, and the modified content in the version library. A common version control system can be divided into two types. One is Centralized version Library (centralized repository)All programmers will submit their changes to a public version library on the server. Specifically, each programmer has a local working directory tree whose content is the latest code in the version library. After the code is modified in the working directory tree, the changes are submitted back to the version library. This method has some limitations. In the local working directory tree, you can only see the latest version of the code. To query historical modification records, you must deal with the version library on the server and use the network. If no network exists, you cannot record the project version that has been modified. The other is Distributed version Library (Distributed repository). With the distributed version control system, you can have your own version library locally. All history records are recorded in the local version library. You do not need to connect to the remote version library when submitting code, it is recorded in the local version library. Git is such a version control system. So how does git upload local modifications to the project's main version library? There are two ways: 1. Upload the modification directly to the master database through the push operation. 2. Generate a patch package containing a small amount of modifications, submit the patch package to the project maintenance personnel, and then update the master version library.
Working directory treeThe working directory tree is a "section view" of the version library ". It includes all the files required to develop the project, including source code files, build files, and unit test files. In git, the version library is not on the server, but is stored in the ". Git" directory in the local working directory tree. How is the working directory tree created? There are two methods. 1. Use Git-related commands to initialize the version library, that is, to generate the ". Git" directory, so the parent directory of the ". Git" directory becomes the working directory tree. 2. Clone an existing version library and create a working directory tree. Cloning an existing version library is to create a copy of the version library and Master Branch)Content Check out)To the working directory tree. In git, checking out is to update the working directory tree and make its content the same as a specific historical version in the version library.
Code modification and file synchronizationAfter the code is modified Submit)These changes. Each commit operation adds a new version Library Version (revision). In addition to recording the changes, the version Library also records the changes Log message)Or Commit message)This is the reason for code changes. During the development process, we sometimes need to share local changes. Therefore, you need to change Push upstream version Library (upstream repository). The upstream version library is a public version library. In contrast to push, we should also be able to get the content in the public version Library to the local version library. Two steps are required. Step 1: Change Fetch)Copy the versions and branches of the remote version Library to the local version library. Step 2: In the local version library, change the changes obtained from the remote version library and local changes made by yourself Merge (merge). Generally, the obtained and merged operations are executed successively. Therefore, you can use a command in git to complete these two steps: Drag (pull). TagA tag uses a simple name (that is, the tag name) to mark a specific point in the version library history. It can be an important milestone, such as the official release of an external version, or a relatively common time point. For example, you can set a tag after fixing a defect. Essentially, a tag is a name that is easy to understand and easy to remember for users. It is used to identify a hard-to-read internal version number in the version library to help users track version history.
BranchUse Branch)This allows your project to move forward with multiple paths. Demonstrate branch principles. Master Branch)Is the main line of R & D, and some version control tools also call the main branch Trunk (trunk).
The Branch is very free. You can merge the branches to the master branch or choose not to merge them. Even you can think of a branch as another trunk, and someone else can pull another branch from your branch.
MergeThe merge operation merges two or more branches. Git compares the changes on each branch to determine where the changes occur and where the files are located. Git can automatically merge the changes when they occur in different parts of the file. However, when a conflict occurs at the same location, a prompt is displayed, waiting for manual intervention. All merged operations will be recorded by git to facilitate future revert or viewing.
SummaryThis chapter introduces several core concepts of git: Version library, version, branch, and merge. The version library is the container of the project-related content, while the version is the view of the project at every moment. Branch and merge provide support for collaboration between teams.

Git (1): git and Version Control Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.