Git Detailed tutorials

Source: Internet
Author: User
Tags commit configuration settings manual diff zip git client git clone git commands
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. How do you do basic source version control before you use a tool? 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
 $ (change patch via e-mail)

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. You tell git through git commit that you want to save a snapshot of the project, and 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.

Catalogue Get and Create Project git use pre-configuration settings git local project development Library default path Configure Local Users and Mailboxes 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 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, as shown below:

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. The following figure:

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 "13241153187@163.com"//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

You can create a git repository by executing git init 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, we execute git init.

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

Now you can see that there is a. Git subdirectory in your project directory. 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 , git init is used 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, and you can do it.

$ 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

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 a. git subdirectory. All of the project data exists there.

$ ls-a
...       . git     README   rakefile lib
$ cd. Git
$ ls
HEAD        Description Info        packed-refs
branches    hooks       logs        Refs
config      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/subsequent item of the URL. 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 repository locally so that you can view the project or make changes. second, the basic snapshot

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

There is an important concept here, Git has a "index" of the east, a bit like your snapshot of the buffer. This allows you to create a series of well-organized snapshots from the changed files, rather than committing all the changes at once.

In short , use git add to add new files and pending changes that need to be tracked, then use git status and git diff to see what's changed, and finally record your snapshot with Git commit. This is the basic process you need to use, most of the time. git add to add files to the cache

In Git, you need to add your modified files to the cache before committing them. If the file is newly created, you can execute git add to add the file to the cache, but even if the file has been traced-that is, it has been submitted-you still need to execute git add to add the newly changed file to the cache. Let's look at a few examples:

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

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

We have two files that have not yet been traced and need to be added.

$ git add README hello.rb

Now that we're done with git status, we can see that the two files have been added.

$ git status-s
A  README
a  hello.rb

In a new project, it is common to add all the files, and you can execute commands in the current working directory: Git Add. Because Git will recursively add all the files in the directory where you executed the command, so if you use the current working directory as a parameter, it will track all the files there. So, git Add. It has the same effect as git add README hello.rb. In addition, the effect is consistent with

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.