Git version control software-Learning manual

Source: Internet
Author: User

Attention:

Please configure the GIT client before learning.

Related article: Git client graphics and details how to install configure GitHub walkthrough

Official Chinese Handbook: Http://git-scm.com/book/zh

Introduction to the GIT Learning manual

This site is for Git to learn the reference manual. The goal is to provide quick access to the most important and common commands for learning and remembering Git. These commands are divided by the types of operations you may need, and will provide some common commands and parameters that you need for your daily use.

This manual will guide you from getting started to mastering. First, we'll start by managing the source code in a way that Git thinks about.

How to think in GIT Way (This section can not understand, then look at the following content, read it all understand.) )

The first important thing to know about Git is that it differs greatly from Subversion, Perforce, or any version control tool you've used. In general, forgetting your version control and thinking about it in Git can help you learn git better.

Let's start from the beginning. Suppose you are designing a new source control system. Before you use a tool, how do you complete the basic source version control work? In all likelihood, you just make a copy of the project when it reaches certain stages.

$ cp-r Project Project.bak

This way, you can easily return to the previous state when things get messy, or compare the current project with the previous copy to see what changes you have made in your later work.

If you are a bit paranoid, you may often make the above mentioned things, and perhaps also add a date to the project copy:

$ cp-r Project Project.2010-06-01.bak

So, you have a bunch of snapshots of the project at each stage to compare and view. With this model, you can also effectively share project changes with people. If you will give it a package when the project arrives at a certain stage, throw it to your website, the other developers can easily download it, make some changes, and give you a patch feedback.

$ wget Http://example.com/project.2010-06-01.zip $ unzip project.2010-06-01.zip $ cp-r project.2010-06-01 Project-my-copy $ cd Project-my-copy $ (made some changes) $ diff project-my-copy project.2010-06-01 > Change.patch $ (by e-mail to send repair FIX)

In this way, the original developer will be able to apply other people's changes to his project, and other developers will be able to understand the changes you have made. This is how many open source projects have been used for years.

That's a good idea, so let's say we want to write a tool that will make it faster and easier. Instead of implementing a tool to record each version of a file, it might be better to implement a tool that makes it easier to create and store snapshots of a project without having to make a copy of the entire project every time.

This is the essence of Git. By git commit telling Git that you want to save a snapshot of the project, Git saves a record of the current state of each file in your project. After that, most of the Git commands are expanded around these records. For example, look at their differences (diff), extract their contents, and so on.

If you think of Git as a tool for sorting, contrasting, and merging project updates, it's easy to understand the situation and do things right.

Catalog fetching and creating projects
    • Git pre-use configuration
    • Set git local project development Library default path
    • Configure Local Users and mailboxes
    • Init
    • Clone
A basic snapshot
    • Add
    • Status
    • Diff
    • Commit
    • Reset
    • RM, MV
Branching and merging
    • Branch
    • Checkout
    • Merge
    • Log
    • Tag
Share and update projects
    • Fetch, pull
    • Push
    • Remote
Check and compare
    • Log
    • Diff
First, get and create the project

You have to have a Git repository before you can manipulate it. The repository is where Git stores the data for the snapshots you want to save.

There are two ways to have a Git repository. In the existing directory, initialize a new one. For example, a new project, or an existing project, but the project is not yet versioned. If you want to copy a project from someone else, or work with someone else, you can clone it from a public Git repository, and second. Both will be introduced in this chapter.

Git pre-use configuration

If set, in the input command interface can be very convenient to use copy and paste (left-click to copy, the right button directly can be copied, paste just click on the right button. ) Set Method: Git Bash shortcut icon (desktop icon) Right-click Properties-Options, the quick edit mode can be checked on it, such as:

Set git local project development Library default path

If you set it up, you don't have to open the directory every time you turn on Git and CD. Method: Right-click Git Bash shortcut icon (desktop icon) properties, find the shortcut-start location, put your project address here on it. Such as:

Configure Local Users and mailboxes

User Name Mailbox role: We need to set a username and mailbox, which is used to upload a local repository to GitHub and display code uploader on GitHub;
Use the command:

git config--global user.name "Hanshuliang"//set user name git config--global user.email "[email protected]"//Set Mailbox

The GIT client has been installed and the GitHub configuration is complete, and now the code can be transferred from GitHub.

Git init Initializes a directory to a git repository

git initYou can create a Git repository by executing it in the directory. For example, we happen to have a directory with some files in it, as follows:

$ cd Konnichiwa $ ls README   hello.rb

In this project, we will write the "Hello World" example in various programming languages. So far, we've only got Ruby, but that's just the road. In order to start versioning this project with Git, let's take a look at it git init .

$ git init Initialized empty git repository in/opt/konnichiwa/.git/# in the/opt/konnichiwa/.git directory to initialize null git repository complete.

Now you can see a subdirectory in your project directory .git . This is your Git repository, and all the snapshot data about your project is stored here.

$ ls-a...       . git     README   hello.rb

Congratulations, now that you have a Git repository shelf, you can start to take a snapshot of your project.

In short , use it git init to create a new Git repository in the directory. You can do this at any time, in any directory, completely localized.

git clone replicates a git repository to ogled

If you need to work on a project with someone else, or if you want to copy a project and look at the code, you can clone that project. Execute git clone [url] , [url] for the item you want to copy, it's OK.

$ git clone git://github.com/schacon/simplegit.git Initialized empty Git repository in/private/tmp/simplegit/.git/remote:counting objects:100, done.remote:Compressing o bjects:100% (86/86), Done.remote:Total (delta), reused 0 (Delta 0) receiving objects:100% (100/100), 9.51 KiB, do Ne. Resolving deltas:100% (35/35), done. $ cd simplegit/ $ ls README   Lib

This will copy the entire record of the project so that you have these locally. And the operation copies the main branch of the project, allowing you to view the code, or edit and modify it. Into the directory, you will see .git subdirectories. All of the project data exists there.

$ ls-a...       . Git     README   Lib$ cd. Git$ lsHEAD        info        packed-refsbranches    Hooks       Logs        refsconfig      index       objects    

By default, Git creates your local project directory with the name of the project indicated by the URL you provide. This is usually the last / thing after the URL. If you want a different name, you can add it after the command, just behind that URL.

In short , use git clone a copy of a Git repository locally so that you can view the item or make changes.

Git version control software-Learning manual

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.