Install and use git in Ubuntu

Source: Internet
Author: User
GIT is a version control tool used 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 Linuxkernel. The most outstanding thing about Git is its mergetracing capability. Installation: Step 1: sudoapt-get

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.

Installation:

Step 1: sudo apt-get install git-core to install the GIT program, or enter git in the new software package and install it.

Step 2: If you have installed git, run the following command to update the version Library.
Git clone git: // git.kernel.org/pub/scm/git/git.git
Step 3: Create a version library git-init-db
It is easy to create a Git version library. You only need to use the git-init-db command.

$ Mkdir gittutorcn
$ Cd gittutorcn
$ Git-init-db

In this way, an empty version library is created and a subdirectory named. git is created in the current directory. You can use ls-a to check the content and pay attention to the following three items:
A file named HEAD. Let's check its content now:

$ Cat. git/HEAD

The contents of the HEAD should be as follows:

Ref: refs/heads/master

We can see that the content in the HEAD file only contains an index information, and this index will always point to the current development branch in your project.
A subdirectory named objects contains all objects in your project. We do not need to know the content of these objects directly. We should be concerned about the data of projects stored in these objects.
A subdirectory called refs is used to store indexes pointing to objects.
Specifically, the subdirectory refs contains two subdirectories: heads and tags, just as their names mean: www.linuxidc.com stores the index of the headers of different development branches, or the index of the tag you use to calibrate the version.

Note: The master is the default branch, which is why. git/HEAD points to the master when it is created, although it does not exist at present. Git will assume that you will start on the master and expand your future work, unless you create your own branch.

In addition, this is just a conventional habit. In fact, you can call your work branch any name, instead of having to have a master branch in the version library, although many git tools think that the master branch exists.

Now a git version library has been created, but it is empty and cannot do anything. The next step is how to implant data into the version library.
Step 4: implant content tracking information: git-add:
To be concise, we create two files as exercises:

$ Echo "Hello world"> hello
$ Echo "Silly example"> example

Use the git-add command to add these two files to the version library file index:
$ Git-add hello example
Git-add is actually a script command that calls git-update-index, the git kernel command. Therefore, the above command is equivalent to the following command:
$ Git-update-index -- add hello example
If you want to clear a file from the git directory tracking system, you can also use the git-update-index Command. For example:
$ Git-update-index -- force-remove foo. c
Git-add can include all contents in a directory under content tracking, for example, git-add./path/to/your/wanted. However, before doing so, you should first clear some files that we do not want to trace, for example, the gcc compiled *. o file, vim swap file. *. swp and so on.

A clear concept should be established: git-add and git-update-index only refresh the git tracking information, the content in the hello and example files is not submitted to the git content tracking scope.

Step 5: Submit the content to the version Library: git-commit
Now that we have refreshed the Git tracking information, let's look at the status of the version Library:
$ Git-status
We can see the git status prompt:

#
# Initial commit
#
#
# Updated but not checked in:
# (Will commit)
#
# New file: example
# New file: hello
#

The prompt message tells us that two new files are added to the version library, and git prompts us to submit these files. We can use the git-commit command to submit them:

$ Git-commit-m "Initial commit of gittutor reposistory"

Step 6: view the current job: git-diff
The git-diff command compares the differences between the current working directory and the version database. Www.linuxidc.com now we edit some files to experience the git tracking function.
$ Echo "It's a new day for git"> hello
Let's compare the differences between the current working directory and the data in the version library.
$ Git-diff
The difference is represented in a typical patch:

Diff -- git a/hello B/hello
Index 802992c .. 8fdaa4e 100644
--- A/hello
++ B/hello
@-1 + 1, 2 @@
Hello world
+ It's a new day for git

At this point, we can use the combined command git-update-index and git-commit again to submit our work to the version library.

$ Git-update-index hello
$ Git-commit-m "new day for git"

In fact, if the files to be submitted are all files already included in the git version library, you do not have to apply the git-update-index Command for these files before submitting them, the following commands are simpler and equivalent to the preceding commands.
$ Git-commit-a-m "new day for git"

Some commands:
Initialize git Database
$ Git-init-db
Add File
$ Git-add hello. c
View modification and submission records
$ Git-log
Create Branch
$ Git-branch roredu
View Branch
$ Git-branch
* Master
Roredu
Switch Work Branch
$ Git-checkout roredu
Switched to branch "roredu"

$ Git-branch
Master
* Roredu

Submit to the current work branch and write the mark.
$ Git-commit-
Create xux branch patch files for the master.
$ Git-format-patch master roredu
Configure the developer's own signature and email.
$ Git-config -- global user. name "roredu"
$ Git-config -- global user. email "roredu@gmail.com"

Modify file name
$ Git-mv roredu. c helight. c
Delete an object
$ Git-rm roredu. c

Collaborate and download the project:
Git-clone ssh @ wtb: 192.168.0.21/home/wtb/NetBeansProjects/project1
Here, wtb is the user name, and 192.168.0.21 is the IP address of the machine where the project is located followed by the project directory and name.

Related Article

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.