Git learning the initial chapter _git

Source: Internet
Author: User
Tags git workflow using git version control system git clone
git what is git

Focus: Powerful distributed, efficient code management tools. Why use.

Emphasis: The use of GitHub community is essential, and indeed convenient and efficient. Version control

Subversion: Centralized version control system, with a single centrally managed server, with a revised version of all files, and working people connect to the server through the client, take out the latest files, or submit updates

Advantage: Everyone can see to some extent what other people in the project are doing. Administrators can also easily control the permissions of each developer, and managing a cvcs is far easier than maintaining a local database on each client.

Disadvantage: A single point of failure of the central server. Failure to submit updates and work together is not possible.

Git: Instead of just extracting the latest version of the file snapshot, the client mirrors the code warehouse completely.

Git differs from SVN

Main difference: How to deal with data
-Git directly records the full file, SVN is the record of the basic files and each file over time cumulative differences


-Almost all of Git's operations are done locally, without networking, and with fast processing.

In the absence of the network can also access history, local modification, submission, and so on, only to push to the remote warehouse when there is a network
-Git keeps data integrity at all times
Before a commit, Git calculates the data-checksum (checksum) and evaluates the result as the unique identifier and index of the data. Check that the data is modified and missing.

Git calculates the checksum of the data using the SHA-1 algorithm, and computes a SHA-1 hash value for the contents of the file or the structure of the directory as a fingerprint string. The string consists of 40 hexadecimal characters (0-9 and a-f) and looks like this:

24b9da6552252987aa493b52f8696cd6d3b00373

Git's work relies entirely on this type of fingerprint string, so you will often see such a hash value. In fact, all the things that are saved in the Git database are indexed by this hash value, not by the filename. Simple configuration of Git

Let's say you've installed git git. Operation level priority (low to High) Description 1 Local Level 2 global User Level 3 system level git document View sample 1 git config–help 2 git h ELP Config command tip enter git conf Double-click the TAB key to automatically supplement the content, similar to the automatic replenishment of the Linux input git config–, double-click tab to display the available parameters

$ git config--
--add              --global           --rename-section
--file=            --list
--replace-all              --local            --system
--get-all          --name-only        --unset       --get-regexp   --unset-all

ADMINISTRATOR@JUST-PC MINGW32 ~/desktop
$ git config--
Configure settings for users and mailboxes before use: equivalent to ID card
git config--global user.name ' xx '
git config--global user.email ' xx@yy '
View User
git config--get user.name  //Currently in use, default latest

git config--list--global//  user all User.Name
Delete User
git config--global--unset user.name user name
Config command
such as creating an alias
git config--global alias.ci commit

Viewing effects, a CI, a commit command alias

$ git c
checkout      Cherry-pick   citool        clone         config
cherry        ci            clean         Commit

$ git config--global alias.lol ' log--oneline '
$ git lol
91b757f Merge remote-tracking branch ' origin/master ' 
  f352b6e Add blog
2c79fcb Create readme.md
21155b9 Initial Commit
GIT's storage

Git stores only relational file content

Git uses a SHA-1 hash of 40 16 characters to store a unique identity object

Git has four kinds of objects:
-Blob text file, binary file, linked file
-Tree Directory
-Commit History Submission
-tag point to fixed history submission

Relationships between four objects: a tag points to a commit,commit point to a tree object, which can also contain other tree objects and Blob objects, and in the case of a file that resembles the same content, points to the same blob, and the file name, etc.

Git stores objects in a warehouse git warehouse creates git warehouse:

GIT init  //new git clone//  clones

Create a specified warehouse

GIT init git_repo//Create Git_repo under. Git directory
git init--bare git_bare_repo  //git_bare_repo There are no. git directories, no workspaces
GIT init  //new directly in current directory

Clone existing Warehouse

git clone git_repo git_clone  //1 Local warehouse clone, specify path

git clone https://github.com/xxx  //2 clone GitHub remote warehouse to current directory
Git workflow

The Git warehouse has three areas:
-Workspace working Direcoty registers staging area, historical warehouse history respository

Inter-zone File delivery:


The commands involved:

git add  //adds workspace files to registers
git add-a//Add workspace All files early registers
git commit///Add staging to History area
git status// View the workspace and registers file
to distinguish git rm  //Delete registers files
git mv//move/Rename registers file, a series of operations of the combination (first deleted after adding)
Gitingnore  / Ignore some files in the workspace that do not want to be added to the registers and history area

And, if only the MV command (no git), then only the local file is manipulated

For Example:

ADMINISTRATOR@JUST-PC Mingw32/g/test/git_repo (Master)
$ touch test.txt a.java  //Create file
$ git add test.txt A.java  //Add to cache
$ git status  //view file status on

branch master
Initial commit

Changes to be committed:< c9/> (use "git rm--cached <file> ..." to unstage)

        new file:   a.java
        new file:   test.txt


ADMINISTRATOR@JUST-PC Mingw32/g/test/git_repo (Master)
$ git commit-m "add Files a"/  /commit to History area

[ Master (root-commit) 02463DD] Add files
 2 files changed, 0 insertions (+), 0 deletions (-)
 Create mode 100644 A.java
 Create mode 100644 test.txt

Here's the status of the file in Git: Not tracked and tracked, view by git status command

Keep in mind that all files under the working directory are in both states: tracked or not tracked. Tracked files are files that are originally included in version control management and have their records in the last snapshot, and their status may have not been updated, modified, or put into registers after working for a period of time. All other files belong to the files that are not tracked. They have neither the snapshot nor the current staging area of the last update. When a warehouse is first cloned, all files in the working directory belong to the tracked file and the status is unmodified.

Simple to understand, as long as the GIT command has been manipulated, the files that are included in Git management are tracked files and files that are not manipulated by the git command are not tracked. For example, when you touch a new file in your workspace, the status is not tracked, add it to the cache using git add, or you've tracked it.

The file state change period in Git is shown below:

If you need to ignore some files, you don't need to be tracked. You can create a. gitignore file in the desired directory location

Wildcard matching rules: Matching rules examples a.txt filter specific a.txt files *~ intermediate type files such as vim~ matching VIM operation generated file * Matching multiple characters *.txt all txt files are ignored [] contains a single character matching list *. [AB] filter files/matching directories ending with a or B/demo filter the current directory Demo folder and folders under All Files **/match any directory under a folder two asterisks/demo, filter any directory ( Contains the demo folder and the files under its folder under the root directory of the. gitignore file! Do not filter!a.txt do not filter a.txt files, if the file itself to the start, you need to add "\" escape, such as "\!a.txt" does not filter!a.txt files

For Example:

ADMINISTRATOR@JUST-PC Mingw32/g/test/git_repo (Master)
$ vim. Gitignore  //Add rule *.css, ignore. css file
$ touch Table.css

administrator@just-pc Mingw32/g/test/git_repo (master)
$ git status   //ignored table.css on
Branch Master Nothing
to commits, working directory clean
More

Welcome to visit my personal blog site: http://jidea.net

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.