Git common commands summary (Super practical)

Source: Internet
Author: User
Tags version control system git commands

Guide Git is a free, open source distributed version control system for agile and efficient processing of any or small or large project. In general, you can use Git as long as you remember 6 commands. But skilled use, I am afraid to remember 60~100 a command.

Here's a list of common Git commands I've compiled. Several special nouns are translated as follows:

Workspace: Work area index/stage: Staging Area Repository: Warehouse area (or local warehouse) Remote: Repository
First, create a new code base
# Create a new Git codebase in the current directory $ git init# create a new directory, initialize it to git code base $ git init [project-name]# download a project and its entire code history $ git clone [url]
Second, the configurationthe configuration file for Git is. Gitconfig, which can be in the user's home directory (global configuration) or under the project directory (project configuration).
# shows the current git configuration $ git config--list # edit git config file $ git config-e [--global] # Set user information when submitting code  "[name]"$ git config [--global] user.email  "[email address]"
third, add/delete files
# Add specified file to staging area$ git add [file1] [file2] ...# Add the specified directory to staging area, including childCatalogue$ git add [dir]# Add all files of the current directory to the temporaryStorage Area$ git Add.# Delete the workspace file and set thisDelete into staging area$ git rm [file1] [file2] ...# Stop tracking the specified file, but the filewill remain in the workspace$ git RM--cached [file]# Rename the file, and put this nameinto staging Area$ git mv [file-original] [File-renaMed]
Iv. Code Submission
# Submit staging area to warehouse area$ git commit-m [message]# Submit the specified file of staging area to the warehouse area$ git commit [file1] [file2]-m [message]# Submit Workspace changes since the last commit, directly to the warehouse area$ git commit-a# Show all diff information when submitting$ git commit-v# Use a new commit instead of the last commit# If the code does not have any new changes, it is used to overwrite the commit information of the last commit$ git commit--amend-m[message]# Redo The last commit and include a new change to the specified file$ git commit--amend
v. Branches
# List all local branches$ git Branch# list all remote branches$ git branch-r# List all local and remote branches$ git branch-a# Create a new branch, but still stay in the current branch$ git branch [branch-name]# Create a new branch and switch to that branch$ git checkout-b [branch]# Create a new branch, point to the specified commit$ git branch [branch] [commit]# Create a new branch to establish a tracking relationship with the specified remote branch$ git Branch--track [branch] [Remote-branch]# Switch to the specified branch and update the workspace$ git checkout [branch-name]# Establish a tracking relationship between the existing branch and the specified remote branch$ git Branch--set-upstream [branch] [Remote-branch]# Merge the specified branches into the current branch$ git merge [branch]# Select a commit to merge into the current branch$ git cherry-pick [commit]# Delete Branch$ git branch-d [branch-name]# Remove Remote Branch$ Git push origin--delete$ git branch-dr
Six, label
# List all tags $ git tag # Create a new tag in the current commit $ git tag [tag] # Create a new tag in the specified commit $ git tag [tag] [commit] # view tag Information $ git show [tag] # submit the specified tag $ git push [remote] [tag] # Submit All Tags $ git push [remote]--tags # Create a new branch, point to a tag $ git checkout-b [branch] [tag]
Vii. Viewing information
# Show files with changes$ git status# shows the version history of the current branch$ git log# shows the commit history, and the file that each commit changed$ git log--stat# Displays the version history of a file, including file renaming$ git log--follow [file]$ git whatchanged [file]# Displays each diff associated with the specified file$ git log-p [file]# shows who the specified file was and what time it was modified$ git blame [file]# Show Staging area and workspace differences$ git diff# shows the difference between staging area and the previous commit$ git diff--cached []# shows the difference between the workspace and the latest commit of the current branch$ git diff HEAD# shows the difference between two commits$ git diff [first-branch] ...[Second-branch]# Show metadata and content changes for a commit$ git show [commit]# shows a file where a commit has changed$ git show--name-only [commit]# shows the last few commits of the current branch$ git reflog
Eight, remote synchronization
# Download all changes to the remote repository$ git fetch [remote]# Show All remote warehouses$ git remote-v# Display information for a remote warehouse$ git remote show [remote]# Add a new remote repository and name$ git remote add [shortname] [url]# Retrieve changes to the remote repository and merge with the local branch$ git pull [remote] [branch]# Upload locally designated branch to remote repository$ git push [remote] [branch]# forcibly pushes the current branch to the remote repository, even if there is a conflict$ git push [remote]--force# Push all branches to the remote repository$ git push [remote]--all
ix. Revocation
# Restore Staging area specified file to workspace $ git checkout [file]# restore a commit file to workspace $ git checkout [commit] [file]# restore all files from last commit to workspace $ git Checko UT. # resets the specified file for staging area, consistent with the last commit, but the workspace is unchanged $ git reset [file]# resets staging area with the workspace, consistent with last commit $ git reset--hard# resets the current branch pointer to the specified commit , while resetting staging area, the workspace does not change $ git reset [commit]# resets the current branch's head for the specified commit, while resetting the staging area and workspace, consistent with the specified commit $ git reset--hard [commit]# Resets the current head to the specified commit, but keeps the staging area and workspace unchanged $ git reset--keep [commit]# creates a new commit that revokes all changes to the specified commit# which will be offset by the former and applied to the current branch $ git revert [commit]

Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/

Git common commands summary (Super practical)

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.