Common git commands

Source: Internet
Author: User
Tags git commands

Installation

Set the user name mailbox after installation is complete
git config--global user.name owl
git config--global user.email [email protected]
New version Warehouse
Git init

Code submission

Submit the file to staging area (stage):
git add < filename >


Put all the folders into staging area
git Add.

Submit files from the staging area to the warehouse (repository):
Git commit


Commit all changes and add comments
Git commit-a-M "comment on this commit file"

Modify the last submitted comment (local)
Git commit-amend

View Changes

See if any files have been modified (before submitting the file)
git status

Discard changes that have been submitted (add)
Git checkout--

See what's changed in a file
git diff < filename >

Version fallback

View previous commit records:
git log
git log--pretty=oneline commit record each line shows one bar

git log--graph displays research and development records in an image

Revert to a previous version
Revert to previous version:
git reset--hard head^

Go back to the first version:
git reset--hard head^^

Go back to the first 100 versions:
git reset--hard head~100


To revert to a future version:
Git reset--hard < version number >

View version number:
Git reflog

Ignore file

Create a. gitignore file (named. gitignore in Windows).
In the list of files and directories you don't want Git to track

#例外的文件类型
*.exe

#例外的文件夹
testdir/

#例外文件 (not backed up)
!my.pyc

Branch Management

#新建分支:
GIT branch < branch name >

Switch branches (preferably commit changes before, or stashing, or commit amending):
git checkout < branch name >

New and switch to branch
Git checkout-b < new branch to switch to > < branch from which the new branch originated (optional) >

# Merging the develop branches (with the--no-ff attribute, the child nodes of the merged branch all fit together)
git merge--no-ff Develop

Delete Branch
Git branch-d < name of the branch to remove >

#把所有没有提交的修改暂存到stash里面
Git stash

#把暂存区stash的数据恢复
Git stash pop

Command shorthand

Add in the Git/config file
[Alias]
CO = Checkout
CM = Commit
St = Status
PL = Pull
PS = push
DT = Difftool
L = Log--stat
CP = Cherry-pick
CA = commit-a
BR = Branch

Linux commands

PWD Displays the current path
CD Switch Directory
mkdir New Directory
Cat View the contents of a text file

Set the starting Bash directory
Gitbash shortcut in the right-click Delete--cd-to-home fill in the starting position

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.