GitHub Detailed Tutorial

Source: Internet
Author: User
Tags diff git workflow sha1 sha1 hash sha1 hash algorithm version control system
GitHub Detailed Tutorial
Table of Contents1 git Detailed tutorial 1.1 git introduction 1.1.1 git is what holy? 1.1.2 Important Terms 1.1.3 Index 1.2 git install 1.3 git configuration 1.3.1 User Information 1.3.2 Highlight 1.3.3 Ignore specific file 1.3.4 use. Gitkeep to trace the empty folder 1.4 start the operation git 1.4.1 Create Content 1.4.2 Create warehouses, add files, and submit changes 1.4.3 diff command with commit change 1.4.4 Status, diff and commit Log 1.4.5 correct submitted information-git amend 1.4.6 delete file 1.5 remote Warehouse Library (remote repositories) 1.5.1 set up a remote git repository 1.5.2 push changes to other warehouses 1.5.3 Add remote warehouse 1.5.4 display existing remote warehouse 1.5.5 clone warehouse 1.5.6 Pull (Pull) Change 1.5.7 Restore changes 1.5.8 Tag 1.6 branch, merge 1.6.1 branch 1.6.2 Merge 1.6.3 Delete branch 1.6.4 push (push) one branch to remote warehouse 1.7 Resolve merge Conflicts 1.8 variable base (Rebase) 1.8.1 applied in the same branch Rebas E-Commit 1.8.2 rebasing multiple branches 1.8.3 rebase best practices 1.8.4 Create and apply patch 1.9 define command 1.10 with same name discard trace file 1.11 Other useful commands 1.12 install git service 1.13 online remote Warehouse 1 .13.1 Clone Remote warehouse 1.13.2 Add remote warehouse 1.13.3 remote operations via HTTP and proxy server 1.14 git service provider 1.14.1 GitHub 1.14.2 bitbucket git graphics interface 1.15 Version e tutorial 1.17 issues with discussion 1.18 links and articles
1 git detailed tutorial
1.1 git Introduction
1.1.1 git is holy?

Git is a distributed version control system developed in C language. The version control system retains the history of a collection of files and can roll back the collection of files to another State (history state). Another state can be a different file, or it can be a different file content. For example, you can convert a collection of files to a state that was two days old, or you can switch between the production code and the experimental code. A collection of files is often referred to as "source code." In a distributed version control system, everyone has a complete source code (including all the history information from the sources), and can operate on this local data. The distributed version control system does not require a centralized code warehouse.


When you make changes to the local source code, you can label them related to the next version (add them to the index) and submit them to the warehouse (commit). Git saves all version information, so you can convert your source code to any historical version. You can submit code to a local warehouse, and then synchronize with other warehouses. You can use Git to perform a clone of the repository, complete with a copy of an existing warehouse. The owner of the warehouse can synchronize the changes through a push operation (a push to a warehouse elsewhere) or a pull operation (pull changes from a warehouse elsewhere).


GIT supports branching functionality (branch). If you want to develop a new product feature, you can create a branch that modifies the branch without affecting the code on the main branch.


git provides command-line tools, and this tutorial uses the command line. You can also find graphics tools, such as the Egit tools associated with eclipse, but these are not described in this tutorial.
1.1.2 Important Terminology

Git terminology

Terminology definition
Warehouse A warehouse includes all version information, all branch and tag information.
Repository Every copy of the warehouse in Git is complete. The warehouse allows you to
Get a copy of your work.
A branch means a separate code line with its own historical information.
Branch (Code line). You can generate a new branch from the existing code
Branches , this branch is completely independent of the remaining branches. The default branch is often called
Master The user can select a branch and select a branch called
Checkout.
Mark A tag refers to the state of a branch at a specific point in time. by Mark
Tags Remember, it is easy to switch to the state of the mark when, for example January 2009 25
Code status on the Testing branch
Submit After the code is submitted, the warehouse creates a new version. This version can be used in
Commit The follow-up was again obtained. Each submission includes author and submitter, author and
The submitter can be different people
Url URL used to identify the location of a warehouse
Used to represent a version state of the code. Git by using the SHA1 hash algorithm
Amendment ID to identify a different version. Each SHA1 ID is 160 bits long
Revision A string of 16 binary identities. The latest version can be obtained by head.
The previous version can be obtained by "head~1", and so on.

1.1.3 Index

Git needs to correlate the changes in the code with the next commit. For example, if you continue to modify a file and then want to submit the changes to the next submission, you must submit the file to the index, using the git Add File command. This allows the index to hold all the changed snapshots.


The new file is always added to the index to be displayed. For files that have been previously submitted, you can use the-a option in the commit command to submit to the index.


1.2 git installation

On Ubuntu, you can install the Git command-line tool with APT


sudo apt-get install Git-core


For other Linux versions, see the relevant Package installation tool usage. The Msysgit project provides a Windows version of Git, the address is http://code.google.com/p/msysgit/
1.3 git configuration

You can prevent git from being configured globally in the. gitconfig file. The file is located in the user's home directory. As mentioned above, each submission saves the author and the submitter's information, which can be saved in the global configuration. The following will describe configuring user information, highlighting, and ignoring specific files.


1.3.1 User Information

Configure the username and email with the following command

git config--global user.name "Example Surname"

git config--global user.email "your.email@gmail.com"
# Set Defau Lt So, changes are always pushed to
the repository git config--global push.default "matching"


Get git configuration information, and execute the following command:

git config--list

1.3.2 Highlighting

The following command highlights the terminal configuration

git config--global color.status auto
git config--global color.branch auto

1.3.3 Ignore a specific file

You can configure GIT to ignore specific files or folders. These configurations are placed in the. gitignore file. This file can exist in different folders and can contain different file matching modes. In order for git to ignore the bin folder, place the. gitignore file in the home directory, where the contents are bin.

At the same time Git also provides a global configuration, core.excludesfile.
1.3.4 use. Gitkeep to track empty folders

git ignores empty folders. If you want version control to include an empty folder, it is customary to place the. gitkeep file under an empty folder. In fact, there is no specific requirement for file names. Once there is a file in an empty folder, the folder will be within version control.
1.4 start Operation git

The following will be learned through a typical git workflow. In this process, you will create some files, create a local git repository, and submit your files to this repository. After that, you will clone a warehouse and Exchange code modifications between warehouses through pull and push operations. The comments (beginning with #) explain the exact meaning of the command, so let's open the command line and start the operation.
1.4.1 Create content

Some files are created below, and they are put into version control

#Switch to Home
CD ~/
# Create a directory
mkdir ~/repo01
# Switch into it
CD repo01
# Create a NE W directory
mkdir datafiles
# Create A few files touch
test01 touch
test02
Touch Datafiles/data.txt
# put a little text into the ' the ' the ' a '


1.4.2 Create warehouses, add files, and commit changes

Each git warehouse is placed under the. git folder. This directory contains all the history of the warehouse, and the. git/config file contains the local configuration of the warehouse.

The following will create a git warehouse, add files to the repository's index, and commit the changes.

# Initialize The local git repository
git init
# Add all (Files and directories) to the GIT repository
git add .
# Make a commits the your file to
the ' local repository git commit-m ' Initial commit ' # show the
log file
git lo G

1.4.3 diff command with commit changes

The git diff command allows users to view changes. By changing the contents of a file, look at what the Gitdiff command outputs, and then submit this change to the warehouse

# Make some changes to the file
Echo ' This was a change ' > test01
echo ' and ' is another change ' > test0 2

# Check the changes via the diff command 
git

# Commit the changes, a'll commit changes for Modifi Ed Files
# but'll not add automatically new files
git commit-a-M "These are new changes"

1.4.4 Status, Diff and Commit Log

The following will show you the current status of the warehouse and the history of past submissions

# Make some changes in the file
echo ' This was a new change ' > test01
echo ' and ' is another new change ' > TEST02 # to the current

status of your repository 
# (which files are changed/new/deleted)
git status
  
   # show the differences between the uncommitted files # and the last commit to the current 
branch
git diff

# A DD The changes to the index and commit
git Add. && git commit-m ' more chaanges-typo in the commit ' # show the history of commits in the current

branch
git log
# This starts a nice graphical view of the CHA Nges
GITK--all

  

1.4.5 Correct submitted information-git amend

With the git Amend command, we can modify the last submitted information. There are errors in the submission information above, and this error is modified below.

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.