Git Common Command Learning manual __unix

Source: Internet
Author: User
Tags configuration settings diff git client using git git clone git commands

Attention:

Please configure your git client before you study.

Related articles: Git client graphic details how to install configuration GitHub operation flow strategy

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

This site for Git Learning reference manual. The goal is to provide quick browsing for learning and memory Git using the most important and common commands. These commands are divided by the type of operation you may need, and will provide some commonly used commands and parameters that are required for daily use.

This handbook will guide you from the beginning to the master. First, we start with how to manage the source code in Git's way of thinking. how to think in a GIT way (this section can not understand, and then look at the following content, read it all.) )

The first important thing to know about Git is that it's very different from Subversion, Perforce, or any version control tool you've used. Often, forgetting the version control you anticipate, and thinking in Git, can help you learn to git better.

Let's start from the beginning. Let's say you're designing a new source code management system. Before you use a tool, how do you complete the basic source version control work? Ten to one, you just make a copy of the project when it reaches certain stages.

$ cp-r Project Project.bak

In this way, you can easily return to the previous state when things get a mess, or make a comparison between the current project and the previous copy to see what changes you have made in the next job.

If you are a bit paranoid, you may often do what is said above, and perhaps add a date to the project's copy:

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

So, you have a bunch of projects at various stages of the snapshot, to compare, view. With this model, you can also effectively share project changes with people. If you're going to give it a packet at a certain stage of the project and throw it on your website, other developers will be able to easily download it, make some changes, and give you 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 modifications)
 $ diff project-my-copy project.2010-06-01 > Change.patch
 $ (send modified patch via e-mail)

In this way, the original developer can apply other people's changes to his project, and other developers can understand the changes you have made. In fact, this is a number of open source projects have been used for many years of collaborative approach.

This is a very good idea, so let's say we want to write a tool to make this approach faster and simpler. Instead of implementing a tool to record the version of each file, we might as well implement tools to make it easier to create and store snapshots of the project without having to make a copy of the entire project every time.

That's the gist of Git. You tell git through git that you want to save a project snapshot, and Git saves a record of the current status of each file in your project. After that, most of the Git commands are spread around these records. For example, look at their differences (diff), extract their contents, and so on.

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

Directory get and create a project Git pre-use configuration settings git Local project development Library default path configuration local user and Mailbox init clone Basic Snapshot Add status diff commit reset rm, MV Branch and merge branch Checkout merge log tag share and update item Fetch, pull push remote check and compare log diff One, get and create Project

You have to have a Git warehouse before you can use it to operate. A warehouse is where Git stores the data for the snapshots you want to keep.

There are two ways of owning a Git repository. In the existing directory, initialize a new one. such as a new project, or an existing project, but the project does not have version control. If you want to copy a project from someone else, or collaborate with someone else, you can clone it from a public Git repository, and two. This chapter will introduce both. Pre-use configuration for Git

If set, in the input command interface can be very convenient to use copy and paste (left to select to copy, point right button can be copied directly, paste just click the right button.) Set method: Git Bash Quick icon (desktop icon) Right-click Properties-option, put the quick edit mode on the hook, as shown below:

set git local project development Library default path

If you set it, you don't have to open the directory every time you open git and CD. Method: Right-click Git Bash shortcut icon (desktop icon) property, find the shortcut-start position, put your project address here. The following figure:

Configuring Local Users and Mailboxes

User Name Mailbox role: We need to set a username and mailbox, which is used to upload the local warehouse to the GitHub, in the GitHub display code upload;
To use the command:

git config--global user.name "Hanshuliang"//Set user name 
git config--global user.email "13241153187@163.com"//Set Mailbox

The GIT client has been installed and GitHub configured to complete and can now transfer code from GitHub. git init Initializes a directory to a git repository

By executing git init in the directory, you can create a git repository. 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 "Hello World" examples in a variety of programming languages. So far, we've only got Ruby, but it's just on the road. To start using Git for version control of this project, we execute git init.

$ git init
Initialized empty git repository in/opt/konnichiwa/.git/
# in the/opt/konnichiwa/.git directory initialization empty Git repository completed.

Now you can see that there is a subdirectory of. Git in your project directory. This is your Git warehouse, and all the snapshot data about your project is stored here.

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

Congratulations, now that you have a shelf of Git warehouse, you can start snapshots of your project.

In short , git init is used to create a new git repository in the directory. You can do so at any time, in any directory, completely localized. git clone replicates a git repository to tried

If you need to work with someone for a project, 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, and 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 objects:100% (86/86), done.
Remote:total (Delta), reused 0 (Delta 0)
receiving objects:100% (100/100), 9.51 KiB, done.
Resolving deltas:100% (35/35), done.
$ cd simplegit/
$ ls
README   Rakefile Lib

The above actions will copy all records of the project so that you have these locally. And the operation will copy the main branch of the project, allowing you to view the code, or edit it, or modify it. Go into the directory and you'll see. git subdirectories. All the project data exists there.

$ ls-a
...       . git     README   rakefile lib
$ cd. Git
$ lshead        description Info        packed-refs
branches    hooks       logs        Refs
config      index       objects

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

In short , use git clone to copy a git warehouse to the local, so that you can view the project, or make changes. second, basic snapshots

Git's job is to create and save a snapshot of your project and compare it to a subsequent snapshot. This chapter describes the commands for creating and submitting snapshots of your project.

Here's an important concept, Git has a "index", something like a cache of your snapshots. This allows you to create a series of well-organized snapshots from the changed file, rather than committing all the changes at once.

In short , add the new files to be tracked and the changes to commit by using git add, and then use git status and git diff to see what changes are made, and finally use git commit to record your snapshot. This is the basic process you want to use, most of the time. git Add file to cache

In Git, you need to add them to the cache before submitting the files you have modified. If the file is newly created, you can add the file to the cache by executing git add, but even if the file has been tracked-that is, it was committed-you still need to execute git add to append the newly changed file to the cache. Let's look at a few examples:

Back to our Hello World example, after we initialize the project, we're going to add our files with git Add. We can use Git status to see the current status of our project.

$ git status-s
?? README
? hello.rb

We have two files that have not been tracked, we have to add them.

$ git add README hello.rb

Now we're going to do it.

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.