Git common Commands list

Source: Internet
Author: User
Tags commit config diff reset root directory git clone

  Three basic concepts

The workspace (Workspace) is the root directory of the items in your computer

Registers (Index) like a cache area, temporarily save your changes

The version library (Repository) is divided into local warehouses (locals) and remote warehouses (sqlremote)

Almost all of the commonly used commands are based on these concepts, a picture of victory, the following is a relatively simple diagram, including the most basic command

But only using the above commands is not enough, in this complex and complicated program world, things are not as simple as you think, but some things to think about is enough, not necessarily to do, you do not have to do it, such as writing a git yourself, but, more understanding of git is what every programmer can do. Then look at the following figure:

The following command combines the above two diagrams to understand, practise, and memorize more effectively. Temporarily do not need to remember the command, do not understand it does not matter, which day encountered problems, and then to find out if there is no suitable method is not too late.

  New/Clone code base

$ git init #当前目录新建一个Git代码库

$ git init [project-name] #新建一个目录, initialize it as a git code base

$ git clone [url] #下载一个项目和它的整个代码历史

$ git fetch [url] #下载/sync project to

 Add/Remove Files

$ git add [file1] [file2] ... # Add specified file to registers

$ git add [dir] # Add specified directory to registers, including subdirectories

$ git Add. # Add all files in the current directory to registers

$ git rm [file1] [file2] ... # Deletes the workspace file and puts this deletion in the registers

$ git RM--cached [file] # Stop tracing the specified file, but the file will remain in the workspace

$ git mv [file-original] [file-renamed] # Rename file, and put this name into registers

  Code submission

$ git commit-m [message] # Submit registers all files to the warehouse area and specify submission instructions

$ git commit [file1] [file2] ...-m [message] # Submit registers specified file to warehouse area and specify submit description

$ git commit-a # Submit workspace changes from last commit, directly to warehouse area. is a combination of git add and git commit

$ git commit-v # Show all diff information when submitted

$ git commit--amend-m [message] # Use a new commit instead of the last commit

 Branch

$ git Branch # list all local branches

$ git branch-r # list all remote branches

$ git branch-a # list all local and remote branches

$ git branch [branch-name] # Create a new branch, but still stay in the current branch

$ git checkout-b [branch] # Create a new branch and switch to that branch

$ git branch [branch] [commit] # Create a new branch that points to the specified commit

$ git checkout [branch-name] # switch to the specified branch

$ git Merge [branch] # Merge Specify branch to current branch

$ git branch-d [branch-name] # Delete local branch

$ GIT push Origin--delete [Branch-name] # method One: Delete Remote branch

$ git branch-dr [Remote/branch] # method Two: Delete Remote branch

  Revoke

$ git checkout [file] # Recover registers's specified file to the workspace (note that the checkout command is required to distinguish between branch operations)

$ git checkout [commit] [file] # Recover a commit's specified file to registers and workspace

$ git checkout. # Recover all files from registers to the workspace

$ git reset [file] # Resets the specified file for registers, consistent with the latest commit, but the workspace remains unchanged

$ git reset--hard # Reset registers with the workspace, consistent with the latest commit

$ git reset [commit] # Resets the current branch pointer to the specified commit while resetting the registers, but the workspace is unchanged

$ git reset--hard [commit] # Resets the head of the current branch to the specified commit, resetting the registers and the workspace, consistent with the specified commit

$ git reset--keep [commit] # Resets the current head to the specified commit, but keeps the registers and the workspace unchanged

$ git revert [commit] # Create a new commit to undo the specified commit

Label

$ git tag # list all tags

$ git tag [tag] # Create a new tag in the current commit

$ git tag [tag] [commit] # Create a new tag in the specified commit

$ git tag-d [tag] # Delete local tag

$ git push origin:refs/tags/[tagname] # Delete remote tag

$ git show [tag] # view tag information

$ git push [remote] [tag] # submit specified tag

$ git push [remote]--tags # Submit all Tag

$ git checkout-b [branch] [tag] # Create a new branch that points to a tag

 View Log

$ git Status # show all change files

$ git Log # Displays the version history of the current branch

$ git Log--stat # Displays the version history of the current branch and the files that have changed

$ git blame [file] # Displays the specified file who changed at what time

$ git log-p [file] # displays each diff associated with the specified file

$ git diff # shows the differences between registers and workspaces

$ git diff--cached [commit] # shows the difference between registers and a commit

$ git diff head # shows the difference between the workspace and the current branch's latest commit

$ git show [commit] # shows changes in metadata and content for a commit

$ git show--name-only [commit] # shows a file with a change in submission

$ git show [commit]:[filename] # Displays the contents of a file when a commit is submitted

$ git reflog # Displays the most recent submissions for the current branch

  Remote Sync

$ git fetch [remote] # Download all changes to the remote warehouse to registers

$ git remote-v # show All remote warehouses

$ git remote show [remote] # Display information for a remote warehouse

$ git remote add [shortname] [url] # Add a new remote repository and name

$ git pull [remote] [branch] # Retrieve remote warehouse changes and merge with local branch

$ git push [remote] [branch] # upload local designated branch to remote warehouse

$ git push [remote]--force # Even if there is a conflict, forcibly push the current branch to the remote warehouse

$ git push [remote]--all # Push all branches to remote warehouse

 Set up

Git's configuration file is. gitconfig, which supports global configuration and project configuration, all of which are valid for all projects, with--global selection specified.

$ git config--list #显示配置

$ git config-e [--global] #编辑 (global) configuration file

$ git config [--global] user.name "XX" #设置 commit user

$ git config [--global] user.email "xx@xx.com" #设置 Commit's mailbox

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.