Common git commands

Source: Internet
Author: User
Tags git commands

In general, the daily use of just remember 6 commands, you can. 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
A new code base # Create a new Git code base in the current directorygit init# Create a new directory and initialize it to git code library git init [project-name] # Download a project and its entire code historygit clone [url]Second, the configuration git settings file for. Gitconfig, it can be in the user home directory (global configuration), or under the project directory (project configuration). # Displays the current git configuration git config--list
# edit git config file git config-e [--global] # Set user information when submitting codegit config [--global] user.name "[Name]"git config [--global] user.email "[email address]"adding/Deleting Files # Add the specified file to staging area git add [file1] [file2] ... # Add the specified directory to staging area, including subdirectories git add [dir] # Add all files from the current directory to staging areagit Add.# before adding each change, will ask to confirm # for multiple changes to the same file, you can implement a sub-commit git add-p # Delete the workspace file, and put this deletion into staging area git rm [file1] [file2] ... # Stop tracking the specified file, but the file will remain in the workspace g It rm--cached [file] # renamed files and put this renaming into staging area git mv [file-original] [file-renamed] IV, code submission # Commit staging area to warehouse area git commit-m [message] # Staging area The specified file to the warehouse area git commit [file1] [file2] ...-m [message] # commit workspace changes since last commit, directly to warehouse areagit commit-a# Show all diff information on commit git Commit-v # replaces the last commit with a new 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 previous Commit and include a new change to the specified file git commit--amend [file1] [file2] ... V. Branch # List all local branches (with * as current branch)git branch
# list all remote branches git branch-r # list all local branches 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 branchgit checkout-b [branch]# Create a new branch, point to specify Commitgit Branch [branch] [commit] # Create a new branch, establish a tracking relationship with the specified remote branch git branch--track [branch] [Remote-branch] # switch to the specified Branch, and update the workspacegit checkout [branch-name]# Switch to the previous branch git checkout-# Establish a tracking relationship between the existing branch and the specified remote branch git branch--set-upstream [branch] [remote-branch] # Merge the specified branch into the current branchgit merge [branch]# Select a commit, merge into the current branch git Cherry-pick [commit] # Delete Branchgit branch-d [branch-name]# Delete Remote branch Git push Origin--delete [Branch-name]git branch-dr [Remote/branch] Six, tag # list all tagsgit tag# Create a new tag in the current commitgit tag [tag]# Create a new tag in the specified commitgit tag [tag] [commit] # Delete local taggit tag-d [tag]# Delete remote taggit push origin:refs/tags/[tagname] # view tag info git show [tag] # submit specified taggit push [remote] [tag]# submit all Taggit push [remote]--tags # Create a new branch, point to a taggit checkout-b [branch] [tag] VII, view information # Show files with changes git status # shows the version history of the current branchgit log# shows the commit history, and each commit changes the file git log--stat # Search commit history, according to the keyword git log-s [keyword] # shows all changes after a commit, each commit occupies a line of git log [t AG] Head--pretty=format:%s # shows all changes after a commit, and its "submission instructions" must match the search criteria git log [tag] head--grep feature # shows the version history of a file, including file renaming git l OG--follow [file]git whatchanged [File] # Displays the specified file related every time diffgit log-p [file] # shows the last 5 commits git log-5--pretty--oneline # shows the Users submitted, sorted by number of commitsgit shortlog-sn# shows what time the specified file is who modified git blame [file] # shows the difference between staging area and workspace git diff # shows the difference between staging area and the previous commit git diff--cached [file] # Show workspace with current branch latest COM Differences between the MIT git diff HEAD # show the difference between two commits git diff [first-branch] ... [Second-branch] # shows how many lines of code you wrote today git diff--shortstat "@{0 Day Ago}" # Show metadata and content changes for a commit git show [commit] # shows a file that has changed in a commit git sh OW--name-only [Commit] # shows the contents of a file when a commit, git show [Commit]:[filename] # shows the most recent commit of the current branch git reflog eight, remote sync # Download all changes to the remote repository git FET  CH [remote] # Show all remote repositories git remote-v # Show information for a remote repository git remote show [remote] # Add a new remote repository and name git remote add [shortname] [url] # Retrieve remote repository changes and merge with local branch git pull [remote] [branch] # upload locally designated branch to remote repositorygit push [remote] [branch]# forcibly pushes the current branch to the remote repository, even if there is a conflict git push [remote]--force # pushes all branches to the remote repository git push [remote]--all nine, undo # Restore Staging Area The specified file to the workspace git checkout [file] # Restore the specified file of a commit to staging area and workspace git checkout [commit] [file] # Recover staging Area All files into the workspace git checkout. # Reset Staging Area specified file, consistent with last commit, but workspace unchanged git reset [file] # Resets staging area to workspace, consistent with last commit git reset--hard # Resets the current branch pointer to the specified commit, Reset staging area at the same time, but the workspace does not change git reset [commit] # Resets the current branch's head to 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] # Create a new commit to undo the specified commit# all changes will be offset by the former and applied to the current branch git revert [Commit] # temporarily remove uncommitted changes and later move to git stashgit stash pop 10, other # Generate a compressed package available for release git archive

From for notes (Wiz)

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.