Common git commands

Source: Internet
Author: User

Git common commands initialize the repository
    • Create a new warehouse to manage existing projects, enter the project directory and enter

      git init

PS: The command will create a. git directory, but will not proactively incorporate the files in the existing project (you need to add them yourself);

    • Clone Warehouse

Four status of files
    1. Untracked not tracked
      The following actions arrive at the non-tracked status:

      新建文件 vi aaa从索引区删除文件  git rm
    2. Unmodified unmodified the following operations arrive in the unmodified state:

      git commit
    3. Modified modified
      To reach the modified state:

       vi aaa
    4. Staged has been staged

      添加 git add
View current status
    • Current status

      git status
    • Status overview

      git status -s

PS: ' MM ' mark: Left M: Modified and put into the staging area, right m: modified not yet put into staging area

    • View differences that have not yet been staged

    • View what is staged and will be added to the next submission

      git diff --staged
Three working areas
    • Git repository
    • Working directory
    • Staging Area

Basic Git Workflow

    1. Modify the file in the working directory.

      vi aaa
    2. Staging file, placing a snapshot of the file into the staging area.

      git add .
    3. Commit the update, locate the file in the staging area, and permanently store the snapshot in the Git repository directory.

      Tracked file modifications are submitted directly to the library:

      git commit -a -m "update file aaa" aaa
Remove files from
    • Remove files from Staging area (also deleted on hard disk)

        
    • Remove files from Staging area (keep on hard disk, this file is no longer tracked)

        
    • Moving files

        
Operation of the staging area
    • Submit Staging

        
    • Supplemental Submissions

        

      It will only show up as a commit at the end

    • Cancel Staging

        git reset HEAD readme

      Change the Readme file from the staging state to the non-tracked state

    • Fallback to the specified version

        git reset --hard :commit_hash_id
View commit History
    • View Logs

        git log
    • Show content differences for the last two commits

        
    • Single-line display

      $git log --pretty=oneline  $git log --oneline --decorate$git log --pretty=format:"%h - %an, %ar : %s"  8029c4c - colin, 10 days ago : add redis_gallery_ad_impr
    • View submission records only for the specified submitter

      $ git log --committer=colin
Remote Warehouse Operations
    • View Remote repositories

    • Update local remote warehouse data pull (not automatically merged into the current working directory):

      git fetch origin git merge origin/serverfix 将origin/serverfix合并到当前的分支
    • Remote data is pulled and merged into the current directory:

      git pull origin

      Automatically pulls and merges data to the trace branch of the remote origin

    • Push to remote Warehouse

      Push the local Serverfix branch as the Serverfix branch of the remote repository

Branching operations Creating branches
git branch testing
Branch switching

Switch to a branch that already exists (HEAD points to this branch)

  git checkout testing
New and toggle

Create a new branch based on the current directory and switch the workspace to the new branch:

  git checkout -b iss53

Create a new branch of Serverfix based on the remote repository origin:

  git fetch origin  git checkout -b serverfix origin/serverfix  or:  git checkout --track origin/serverfix
Trace Branch
    • Set trace settings an existing local branch tracks a remote branch that has just been pulled down, or wants to modify the upstream branch being traced:

      git branch -u origin/serverfix
    • Query tracking Relationship View all trace branches of the setting

      git branch -vv
Delete Branch
    • Delete local Branch

      git branch -d hotfix
    • Delete Remote Branch

      git push origin --delete serverfix
Branch Merge
    • Merging merge Merge Iss53 branch to Master Branch (PS: The merged branch is the current workspace)

      git checkout mastergit merge iss53
    • A variable-base rebase is a sequence of commits that are applied to another branch in the order in which they were originally ordered, and the merge is the final result combined.

      git checkout experimentgit rebase master
View the current branch list
git branch

Ref: "Pro Git 2.0"

Posted by: Big CC | 14may,2016 Blog: blog.me115.com [subscribe to]github: Big cc

Common git commands

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.