Git-the stupid content tracker, A dummies content tracker. This is how Linus introduced git.
Git is a version control tool for Linux kernel development. Unlike common version control tools such as CVS and subversion, it uses a distributed version library without the support of the server software, making it extremely convenient to publish and exchange source code. Git is fast, which is naturally important for large projects such as Linux kernel. Git's most outstanding 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, git's normal use is executed by some friendly script commands, making git very easy to use. Git is friendly even for managing our own development projects, powerful tools. Now, more and more famous projects use git to manage project development, such as wine and U-boot.
Note:
This book introduces a lot of content, especially the discussion on multi-person cooperation and distributed project management. After learning a series of git commands, how can we effectively use them to manage projects and cooperate with others? Pro git discusses these issues in chapter 5. In this way, you do not have to explore it yourself.
This chapter describes the knowledge before using git. We will first understand the historical background of some version control tools, and then try to run git on your system until the final configuration is complete, you can start normal development. After reading this chapter, you will understand why git is so popular and why you really need to use it.
Pro git Chinese version PDF:
Free in http://linux.linuxidc.com/
The username and password are both www.linuxidc.com
The specific download directory is available in/July 15,/July 29/Pro git Chinese version PDF
Or Baidu Network Disk download: http://pan.baidu.com/share/link? Consumer id = 590883 & UK = 487907638
Attached tips:
Why use git?
- Smoother workflows and full offline operations during development
- Fast. The GIT distributed architecture allows the local repository to contain all historical version information. You can quickly switch between different versions.
- An elastic local branch. In SVN, You need to copy the source code to another folder to build a branch. In git, the cost of creating a branch is very small. Only one command is required.
- The repository directory structure is concise. You can use git to copy a project and only create a. Git directory in the project root directory, while other directories are clean.
- The content is stored in metadata. All version information is stored in the. Git directory.
- Good integrity, easier collaborative development
- A large user base. There are already thousands of open-source projects using git for project management, and there are countless code repositories on GitHub.
Git installation and configuration
Install
1. Install from source code
Before installation, you must ensure that the following dependent packages have been installed on your system: curl, zlib, OpenSSL, expat, and libiconv. If your system is Ubuntu, you can install it like this:
Apt-Get install curl-devel expat-devel gettext-devel OpenSSL-devel zlib-devel
When all the dependencies have been resolved, you can download the gitsource code from http://git-scm.com/downloadand compile and install the code later:
Tar-zxf git-1. * .tar.gz
CD git-1 .*.*
Make prefix =/usr/local all
Sudo make prefix =/usr/local install
2. Install
If your system is Linux or fedora, you can install git directly using the following command:
Yum install Git-core (Fedora)
Apt-Get install Git-core (UBUNTU)
3. install on Windows
Although git originated from Linux, git can be used normally on windows, but it does not support Chinese characters. in windows, all Chinese characters are displayed with question marks. In addition, there are some functional bugs. Therefore, it is recommended to use git on Linux. If you have to work on Windows, you can. By default, the GIT bash and git GUI programs are installed in msysgit. Generally, you can use git bash, which supports common commands. If you are not familiar with Linux Command lines, you can also use the git gui, but the features are limited.
Use git for the first time
After installing git, You need to modify some configurations to use git normally.
Git uses the "Git config" command to configure git. This command has two options: -- system, -- Global, and the default options, which correspond to three levels of configuration files on git respectively. The first one is the/etc/gitconfig file, which corresponds to -- system. This is a global configuration file. modifying this file will affect all users and warehouses in the system. The second is the/. gitconfig file in your directory, which corresponds to -- Global. modifying it will affect all the repositories of your current user. The third is the. Git/. gitconfig file in your repository. This is the default configuration file modified by "Git config". It will only affect your current repository.
When you use git for the first time, you need to tell your co-developers who you are and your email address. When you submit, git needs the two information. Run the following command to set the parameters:
Git config -- global user. Name "test oss"
Git config -- global user. Email [email protected]
You can also choose not to use the -- global option, but this means that you must set it in every repository.
You can also specify your editor, your diff tool:
Git config -- global core. Editor Vim
Git config -- Global merge. Tool vimdiff
You can also run the "Git config -- List" command to view your settings.
After you set up git, if you want to obtain a repository from the GIT server or submit your code (such as GitHub) to the GIT server ), you may need to generate your own SSH key pair. Git supports four protocols for communication with the server: git, HTTP, ssh, and HTTPS. Git is only a read-only protocol, that is, you can only obtain the Repository from the server, but you cannot submit your own code. HTTP and HTTPS are rarely used. Most of them only support the SSH protocol and git protocol.
When you use the SSH protocol to communicate with a remote server, you can use the following command to generate an SSH key pair:
Ssh-keygen-T RSA
If you do not specify the key name and storage path, it places two asymmetric keys under your home directory by default. in the SSH directory, the default names of the key files are id_rsa and id_rsa.pub. The former is the private key and the latter is the public key. In the middle, you may need to set an access key password, which can be set or not. However, we recommend that you set an access key for security considerations. Otherwise, it means that anyone holding your key can use it.
Then, send your public key to the GIT repository administrator, and then you can access the server through the SSH protocol. During this period, the program automatically matches the key pair. If you set the access password, you may need to enter the password.
For more information about SSH, visit here: http://www.freebsd.org/doc/zh_CN/books/handbook/openssh.html
After completing these settings, you can obtain any public code repository to check whether your git works normally. For example:
Git clone git: // git2.kernel.org/pub/scm/git/git.git
Git Repository
As a resource management and tracking system, if you want to host your files on git, you must first let git know where the files you need to manage are. For example, if I have a project in the test folder and want git to manage the project, you need to enter the Directory and run the "Git init" command. At this time, git will generate a hidden. Git directory under this directory. All the files that git uses for version control and content tracking are in this folder.
Only three States are available for files tracked by git:
- Modified (working directory): Modified File
- Staged (staging area): Files Added to the temporary storage area through git add
- Committed (GIT directory): file submitted to the repository through git commit
Therefore, the general Git workflow may be like this: you have modified some files, added these files to the hold zone, and then submitted them to the repository to form a version or snapshot, finally, submit it to the GIT server. In the middle, it may be accompanied by branch management, branch switching, withdrawal, and merge.
Some may find it strange that git has the concept of temporary storage zone, and it is not okay to submit it directly to the repository. In fact, this is GIT used for version control. Imagine that if there is no temporary storage area, a version will be formed for every file modification, which is too frequent and difficult to manage. The temporary storage area is actually the file list of the next version. You can freely control what files should be submitted to the warehouse. This also avoids some intermediate files in a version, for example, the compiled file.
Pro git CN plus