Git version management tool (1)

Source: Internet
Author: User
Tags hosting mercurial git commands

GitLinus Torvalds, a distributed version control tool, introduced Git-the stupid content tracker (silly content tracker)


1. Git background

Git was originally written by Linus Torvalds and used as a version control tool for Linux kernel development.

Git is different from common version control tools such as CVS and subversion. It uses a distributed version library without the support of server software, making it extremely convenient to publish and exchange source code.

Git is very fast, which is naturally important for large projects such as Linux kernel. The most outstanding thing about git is its merge tracing capability.

In fact, when the kernel development team decided to start developing and using git as the version control system for kernel development, there were a lot of objections from the open-source community in the world. The biggest reason is that git is too difficult to understand, from the perspective of git's internal working mechanism, this is indeed true. However, with the development in depth, normal use of git is executed by some friendly script commands, making git very easy to use, even if it is used to manage our own development projects, git is a friendly and powerful tool. Now, more and more famous projects use git to manage project development, such as wine and hiphop-PHP.

Git, as an open-source and free-thinking project, does not impose any permission restrictions on the browsing and modification of version libraries. However, it can achieve limited permission control through other tools, such: gitosis, codebeamer mr. Originally, git is only applicable to Linux/Unix platforms, but is gradually mature in the use of Windows platforms, mainly thanks to the easy-to-use GUI tools such as cygwin and msysgit environments and tortoisegit. In fact, the source code of git has added support for cygwin and mingw compiling environments and has been gradually improved. It is a good news for Windows users.

2. Why git?

Popular open-source software version management software, including CVs, SVN, and git version management tools. What are the advantages of git?

Git getting started tutorial. Please check my Baidu space blog:Blog

Unlike CVs and Svn, git is a distributed source code management tool. It is very powerful and fast. the Linux kernel code is managed by git, which brings us the direct benefits:

1. initialization, git init, git commit-a, is complete. For anyone who writes two lines of code to the code management tool, it is not suitable. You can also use git as a backup system or synchronize the documents of the two machines.

2. Most of the operations are done locally, without interacting with the code management server in the cluster, and finally you can boldly check in code anytime and anywhere. Only the final version must be submitted to a centralized code management server.

3. Each commit creates a unique commit ID for all codes. Unlike CVs, the version of a single file is changed separately. Therefore, you can check all the code before a certain submission at a time without considering the files submitted. (SVN can also do this)

4. branch management is much easier. No redundant directories need to be created, either by creating a new branch or by switching between branch.

5. When branch is merge, not only will the code be merge together, but the check in history will be retained, which is very important.


Git has the following advantages:

1. More convenient merge

Distributed Management will inevitably lead to a large number of branch and merge operations. Therefore, the distributed version control system pays special attention to this aspect. Creating branch and merge in traditional CVS is a nightmare. As a system used to replace CVs, subversion improves branch operations. However, it seems that branch is easy, but what about merge? If merge cannot return easily, branch is still a nightmare. As a matter of fact, I 've experienced a lot of code overwrites in merge due to incorrect operations on my teammates in the development team. The Subversion was used at that time. Although the source code is still in the history, it is really unforgettable to find the overwritten files one by one and restore them.

2. More convenient management

The traditional version control system uses a central warehouse, and some warehouse-related management can only be performed on the warehouse. It is very difficult to assign the management permissions of each person in the development team to the central warehouse. But sometimes it is inconvenient.

3. More robust systems

Distributed systems are generally more robust than single-server systems, because the entire system cannot run once the server fails. However, distributed systems are generally not affected by one or two nodes.

4. Less network-dependent

Although the network is very popular today, it does not have high-speed networks anytime, anywhere, or even sometimes there is no network to access. Low-speed networks can make people feel annoyed. Sometimes they just stare at the commit progress on the screen and cannot do anything. No network connection is even more fatal: you cannot commit! This means you must be careful before making any changes, or you may no longer find some code you have written.

5. Less "warehouse pollution"

Sometimes you need to create a module. It is not too large, so there is no need to create a branch for it, but it is not that small. It is impossible to do it right after one commit. Therefore, some incomplete code will be submitted to the warehouse, and sometimes the entire program will not run, seriously affecting the development of other people in the team. In this case, most people Submit the solution after writing it. However, for those who are used to version control, it is often a matter of making major changes without any consequence. Later, they suddenly find that their previous Code has not been submitted, and then they regret it. If it is a distributed system, there will be no such problem, because the modification of the Local warehouse will not affect others' warehouses. After you complete the test, you can say in the mail list: I have completed this module. Then the people you are interested in will be able to pull your achievements from you.

Although the reputation of Git on the Internet never stops, on the GIT website, git and subversion are compared as objectively as possible (gitsvncomparsion ). In addition, subversion currently uses SVK to provide distributed management capabilities for source code libraries, enabling offline submission of source code.

 


3. Git, CVS, and SVN comparison

In the project source code version management tools, the main commonly used tools include CVs, SVN, git, and mercurial (for details about SVN, see my previous blog: common SVN commands and SVN server configuration)

Currently, Google Code supports three methods: SVN, git, and mercurial. For example, I uploaded Linux-kernel-source (GIT mode) and SDK-Java (SVN mode ), so what are their differences?


Differences between git and CVS

  • Branches are faster and easier.
  • Supports offline work. Local submission can be submitted to the server later.
  • Git commit is atomic and the entire project scope, unlike in CVS, it is for each file.
  • Each work tree in git contains a repository with a complete project history.
  • No git repository is inherently more important than other repositories.


Differences between git and SVN

Git is not only a version control system, but also a Content Management System (CMS) and a work management system. If you were a person with a SVN background, you can easily switch ideas to adapt to some concepts and features provided by git. The main purpose of this article is to introduce what git can do and what is the difference between git and Svn in depth. Through comparison, we can help you better understand git.

  1. Git is distributed, SVN is not

    This is the core difference between git and other non-distributed version control systems (SVN, CVS. If you can understand this concept, you will be half done. You need to make a statement that git is not currently the first or only distributed version control system. Some other systems, such as bitkeeper and mercurial, are also running in the distributed mode, but git is doing better in this aspect and has more powerful features.

    Git and SVN have their own centralized version libraries or servers. However, git is more inclined to be used in the distributed mode, that is, each developer will clone a version library on their own machine after chect out code on the server of the central version library. It can be said that if you are stuck in a location that cannot connect to the network, like on the plane, in the basement, in the elevator, you can still submit files and view historical version records, create a project branch. For some people, this seems to be of little use, but when you suddenly encounter an environment without a network, this will solve your major troubles.

    Similarly, this distributed operation mode is also a huge gift for the development of open-source software communities. You do not have to make a patch package as before and send it by email, you only need to create a branch and send a push request to the project team. This keeps your code up to date and won't be lost during transmission. An outstanding example is github.com.

    It is rumored that the future version of subversion will also be based on the distributed mode. At least not yet.

  2. Git stores the content in metadata mode, while SVN stores the content by file

    All resource control systems hide the object metadata in a folder such as. SVN and. CVs. If you compare the size of the. Git directory with that of. SVN, you will find that they are quite different. Because the. Git directory is a clone version library on your machine, it owns everything on the central version library, such as tags, branches, version records, and so on.

  3. Git branch and SVN branch are different

    The Branch is not special in SVN, that is, another directory in the version library. If you want to know whether a branch is merged, You need to manually run a command like thisSVN propget SVN: mergeinfoTo check whether the code is merged. Therefore, some branches are often missed.

    However, it is quite simple and interesting to process git branches. You can quickly switch between several branches in the same working directory. You can easily find unmerged branches. You can easily and quickly merge these files.

  4. Git does not have a global version number, while SVN does

    So far, this is the biggest feature missing from git compared with SVN. You also know that the SVN version number is actually a source code snapshot of any corresponding time. It is the biggest breakthrough from the evolution of CVS to SVN. Git can use SHA-1 to uniquely identify a code snapshot, but this does not completely replace the easy-to-read numeric version number in SVN.

  5. The content integrity of git is better than that of SVN

    Git uses the SHA-1 hash algorithm for content storage. This ensures the integrity of the Code content and reduces the damage to the version library in case of disk or network problems. This is a good discussion about the integrity of git content. (For more information, see diff)


Comparison of CVS-SVN-GIT

First, introduce the important basis for comparison between several version control software:

(1)Version Library Model: describes the relationship between multiple source code version database copies. There are two modes: Client/Server and distributed. In Client/Server mode, each user accesses the master database of the server through the client. Each client only needs to save copies of the files it is concerned with and working copy) only after the changes are submitted to the server can other users see the changes to the corresponding file. In distributed mode, the copies of source code version libraries are equivalent entities. In addition to the Working Copies, users' machines also have historical information about local version libraries.

(2)Concurrency model (concurrency model): describes how to manage such conflicts when changing or editing the same working copy/file at the same time to avoid meaningless data, including exclusive locks and merge modes. In the exclusive lock mode, only the user who sends a request and obtains the exclusive lock of the current file can modify the file. In merge mode, users can edit or change files at will, but they may be notified of conflicts at any time (two or more users edit the same file at the same time ), therefore, version control tools or users need to merge changes to solve such conflicts. Therefore, almost all distributed version control software adopts the merge Method to Solve concurrency conflicts.

(3)History model: describes how to store file changes in the version library. There are two modes: snapshot and change set. In snapshot mode, the version library stores the working copies before and after the change. In change set mode, the version library saves the working copies before the change, only the information about changes after the changes are saved.

(4)Scope of change: describes whether the version number is for a single file or the entire directory tree.

(5)Network Protocol (network protocols): Describes the network protocol used for synchronization between libraries of multiple versions.

(6)Atomic commit: Specifies whether all changes can be committed, merged, or not changed when a change is submitted.

(7)Partial checkout/clone: whether to copy only the specified sub-directories in the version library.

 

Name

Version Library Model

Concurrency Mode

Historical Mode

Change Scope

Network Protocol

Atomic committing

Partially cloned

CVS

Client-server

Merge

Changeset

File

Pserver, SSH

No

Yes

SVN

Client-server

3-way merge, recursive

Merge, octopus merge

Changeset and snapshot

Tree

Custom (SVN), svn m (SVN) over SSH,

HTTP and SSL (usingwebdav)

Yes

Yes

Git

Distributed

Merge or lock

Snapshot

Tree

Custom, custom over SSH, rsync,

HTTP/https, email, Bundles

Yes

No

Trunk, branches, tags differences:

Trunk: the Main Line in the software development process. The directory where the versions are stored during development, that is, the code in the development stage is submitted to this directory, saving the information created from the version Library to the current one.

Branches: the branch in the software development process. The directory where the released version is stored, that is, the stable version released when the project is released, is stored in this directory, saves the information from a specific point of the version Library (not necessarily when the version library is created) to the current.

The Branch is mainly used for exploratory or experimental development of new functions without affecting other trunk users. It can also be merged into trunk after the new functions are completed.

(For the original article, refer to my blog in Baidu space: git command parameters and usage details)



4,GitUse on Windows

Git was born for Linux. It was first created by Linus Torvalds, the founder of Linux.

In Linux, using git is no different from any command line tool in Linux, and even has obvious advantages in the number of clicks.

In Windows, there are only two methods to use git:

1. UseCygwin(A Linux environment running on Windows)

2. UseMsysgit(GUI and command line are provided in Windows)

Cygwin and msysgit are used in a similar way. cygwin has a large number of Linux functions. If you just want to use the GIT function, msysgit is the simplest and fastest way.

In order to be able to achieve collaborative development with others through the Internet, a public source code hosting service is required for the project. Fortunately, there are already many options available for us, especiallyGithostIs a Chinese source code hosting service provider. At present, there are few projects settled on githost, and it seems to be a new service provider. If the project has high requirements on the stability of the Service, it is better to choose the old git source code hosting service. If you are working in a LAN group and want to use git for source code management, it will be simpler. You have installed your own git, and designate a person to manage the GIT version library.

(1) GitHub Introduction

GitHub is developed using Ruby with a refreshing interface.

GitHub provides free source code library hosting and paid hosting services. You can use the paid private database hosting service to support the continuous operation of the free part of the finance.

GitHub provides a unique code library management interface and a project wiki.

GitHub provides a series of guides on the official website: GitHub

(2) install git on Windows

First, download and install the msysgit program: Download

Next, install the downloaded Git-1.7.10-preview20120409.exe, you can choose the latest git version, to achieve better use.

The installation process is simple. You can use the default settings. When setting the path, you should pay attention to it. To avoid exceptions caused by Windows paths, it is safer to use "use git bash only.

Msysgit can be used in command line and graphic UI. Choose one based on your preferences. However, the graphic UI may not be able to complete all the work, therefore, in some cases (such as creating an SSH key), the command line is still necessary. The bash command line of msysgit does not provide good support for Chinese characters. All Chinese characters are displayed as "?". Therefore, we recommend that you do not use Chinese file names, directory names, and user names to avoid any problems.

The msysgit graphic interface is as follows:

(For the original article, refer to my blog in Baidu space: git interface GUI and command line command)

(3) set GitHub

To use GitHub, you must first create an SSH key. SSH will be used to encrypt the communication between the local server and the remote server, and also to identify your changes to the Code.

SSH key can be generated using the GIT command line. If you already have an SSH key, you can also use it directly here.

To create an SSH key using git, first open the GIT bash command line and enter the command:

Ssh-keygen-c "username@email.com"-T RSA

(Username@email.com needs to change to your own email address)

The program will raise some questions and accept the default storage location of the file. If you need to input pass phrase, you can leave it empty if the local security is normal. Find the id_rsa.pub file in the specified file storage location. This is the SSH public key file used to apply for an account on GitHub.

Select free account in register of github.com, and enter the corresponding content in the subsequent interface as required to complete registration, which is very simple.

5. Git services

1. Create a git Remote Server:

At present, it seems that the GIT server has not been built on windows, which shows the powerful advantages of Linux in the open-source community! Pai_^

Hosting git repositories, the easy (and secure) way: gitosis

2. Git-based source code hosting

Gitorious

Gitorious is another free hosting site with a custom web interface, supporting multiple repositories per project, local installations and with open source

Repo. Or. cz
Repo. or. CZ is the oldest hosting site, accommodating contains hundreds of projects, with open-sourced infrastructure and aimed at open source software. it provides full push features as well as simple processing mode and gitweb interface with varous enhancements.

GitHub
GitHub provides both free hosting for smaller projects and paid options for private hosting and large-sized projects. It uses a custom web interface including a wiki hosting and puts emphasis on social networking of project developers

3. Useful connections for git:

Git-SCM: Go URL

Git reference: Go URL

Git-SVN crash course: Go URL

Everyday git with 20 commands or so: Go URL

Git User's Manual (for version 1.5.3 or newer): Go URL

Getting started with GIT and GitHub on Windows: Go URL

Note:For the original article, see using the version management tool git in my blog Windows environment in Baidu space.

Reference recommendations:

Git command parameters and Usage Details

Common git commands (charts)

Common SVN commands

SVN Server Installation

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.