GIT Cheat Sheet

Source: Internet
Author: User
Tags commit diff git clone git cheat sheet

Http://files.cnblogs.com/lbsx/git-cheat-sheet-large.png.zip


One: Overview

There are countless books on the web for Git and cheatsheet. But its editorial thinking is to explain the order. Always wanted this article cheatsheet: in daily use of git, I will encounter which uses case, what is the priority of these usage case, what should be used git command. For this idea, edit this article.

The goal of this article is to understand the basic concepts of git, but it's not long (half a year) to remember so many commands, to do things without knowing which command to use, and the user who needs a quick look at the table.

Two: Use case and order

All use case is sorted by priority, but with branch coherent use case

Level Case Commands and examples Comments
P0 Copy Remote Repository git clone git://git.xxx.com/xxx/xxx.git Meaning to download the code
P0 Download updates for remote repository git fetch Unlike other version management tools, the code downloaded in git is invisible in workspace and is not visible until merge or rebase.

P0

Merge updates and local updates for remote repository that have already been downloaded git rebase or git merge It is recommended to use Git rebase because this code history is linear to see clearly. There are only a few special cases where Git merge is recommended, such as a code conflict, and you're not planning to upload code to the remote repository for the moment.
P0 Simultaneous download of remote updates and local merge Git pull or git pull--rebase Git pull = git fetch + git merge
Git pull--rebase = git fetch + git rebase
P0 Staging New or modified code git add git Add. You can staging all changes in this directory and sub-directories
P0 Submit code to local repository Git commit-m "" Unlike other version management tools, the commit code in GIT is only submitted locally, invisible to others, and then seen by other git push.
P0 Upload the local repository code to the remote repository git push The general omitted parameter, that is, pushes the code of this branch to Origin repository the same name branch
P0 Resolve Code Merge conflicts It is recommended to solve the graphical interface of tools such as Tortoise Git or EGit plugin, and the command line is more complex
P0 Git Common global configuration git config--global user.name ' xxxxx '
git config--global user.email ' xxxxx '
git config--global core.autocrlf input
git config--global push.default upstream
git config--global branch.autosetuprebase always
git config--global core.editor vi
git config--global credential.helper cache
For an exhaustive list, see Https://git-scm.com/docs/git-config

If you want to use different user names and mailboxes in different projects, remove the--global option

In Windows platform, use git config--global credential.helper wincred
P1 Notifies git to be ready to delete files git rm
P1 Undo local Changes 1 git reset [--hard] < file name > Revokes the staging state of the local file into the modified state, but the code changes remain in the workspace
P1 Undo Local Changes 2 git checkout--force Revokes the staging state of the local file and revokes changes to the code in the workspace.
P1 Undo local Changes 3 Git clean-dn Delete the local untraced file. Combine git checkout--force to perfectly undo all local changes
P1 View all changed code (file level) git status
P1 View all changed code (line level of code) Git diff The result of Git diff is the standard diff file format
P2 View Code change history git log
P2 View the history of each branch head Git reflog Git reflog can see the deleted commit, and git log cannot



P2 To configure a text file to enter a newline conversion mode git config core.autocrlf= Configuration is required only under the Windows platform, and the Linux platform does not need to be configured. Windows platform recommended false (requires an editor that supports Linux-formatted text)
P3 Set a file to not commit git repository Edit. gitignore file Note: Files that are already in repository will ignore the. gitignore file
P3 If a file is already in Git repository, notify git to forcibly ignore the file modification Git update-index--assume-unchanged
P3 Notifies git recovery tracking of changes to the file Git update-index--no-assume-unchanged
P3 Set pull default with Rebase mode Modify. git/config, Increase rebase = TRUE or modify ~/.gitconfig increase autosetuprebase = always
P3 View details of a commit in history Git show
P3 Create a new empty repository Git init--bare
P3 Hit label git tag
P3 View the last author of a line of code (that is, blame) git blame <-l linea,lineb>
P4 Two-part method for locating the wrong commit Git bisect

General usage

git bisect start
Git bisect
git bisect good

Br List all local branch Git branch "Master" branch is the main branch, the current branch is marked *
Br List all local and remote branch Git branch-a
Br Switch to a branch development Git checkout Switching to local branch is generally
Br Create a remote branch Three steps
Git branch
Git checkout
Git push origin
Br Create a local branch based on a remote branch Git checkout This command is actually a git checkout-b--track/abbreviation
Br Remove Remote Branch Git push origin:
Br Merging branches git merge
Br View the direct upstream branch of this branch Git branch--merged
Br See changes between two branch Git show Brancha. Branchb
Br See changes between two branch 2

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.