It took a little time to familiarize yourself with and sort out common git commands.
Recommended git learning materials:
1. Search for "Git community book Chinese edition" and git community book. The content is comprehensive and concise. The first recommendation
2. southeastgithute.aliyun.com. However, it is too thick and can be used as a document query.
3. Go to progit and read "http://git-scm.com/book/zh.pdf", which is very well written. You can select the previous chapters as your preliminary students. But the content is not enough.
I first scanned several chapters in Chapter 3, and then read 1, which is basically enough. Occasionally query 2.
It seems that the graphic version change diagram is very important, so we recommend that you pay attention to it.
The following content is organized:
Operation steps and command sorting
Install
Yum install Git-core // RedHat or other systems using yum
Apt-Get install Git-core // Ubuntu or other systems that use apt-Get
Configuration
Git config -- Global // configure user name and email
Local Command
Git init // initialize the current directory
Git add // trace file, or add file to the temporary storage area. Note that add is a multi-purpose Command, which has different meanings depending on the status.
Submit
Git commit // submit the temporary storage area file to the repository
Git commit-A // submit the files that have been modified in the workspace and files in the temporary storage area to the repository.
Git commit -- Amend // Modify the last commit, or overlay the last commit.
Network commands
Git clone // get the repository and put it under the local origin name
View status
Git status
View submission history
Git log
File comparison
Git diff // compare the working file with the saved file
Git diff -- cached // save files and submitted files
Git diff -- staged // save files and submitted files
Remove a file
Git RM
Git Rm -- cached readme.txt // remove the file from the temporary storage zone and repository. This file will not be tracked in the future.
Move or rename
Git mv
Cancel temporary storage
Git reset head filename
Reset
Git reset -- hard head // reset the working directory (excluding untracked files)
--------- To restore a single file, you can checkout the file: git checkout -- filename
Rollback
Git revert head // roll back to the previous commit
Git revert head ^ // roll back to the previous commit. You can add "^" to return to the previous commit.
--------- Note that after revert is rolled back to the working directory, you can immediately create the latest commit, which is equivalent to copying an old version to the latest location.
Merge
Git merge hotfix // merge the hotfix branch to the current branch. Note: Only merged. The merged result is not submitted to commit.
Git merge upstream/Master // merge a remote Retrieval Branch
View differences
Git diff hotfix // view the differences between the current Branch and the hotfix Branch
Git diff // compare the working directory and temporary directory (index or temporary directory)
Git diff -- cached // compare the temporary directory (index or temporary) and the last commit
Storage
Git stash "Why stash or other" // save a status
Git stash apply // restore
Git stash list // display previous stash Information
Git Stach [email protected] {number ?} // Restore a stash
Git stash clear // clear the queue
Search
Git grep string // search for a string
View Branch
Git branch // view local branches
Git branch-r // view remote branches
Create and jump to Branch
Git branch mybranch // create a branch, but it is not set to the current Branch
Git checkout mybranch // extract a branch as the current Branch
----- Combine the above two steps: Get checkout-B mybranch
Delete Branch
Git branch-D branch name
View which remote warehouses are available
Git remote
Git remote show
Git remote show repository name // View Details of a remote Repository
Add remote repository to Local List
Git remote add [local abbreviation] [remote URL] // Add a local abbreviation to the remote Repository
Git remote rename old name new name // modify local abbreviation of remote Repository
Git remote RM branch name // Delete the local connection of the remote Repository
Capture updated data from a remote warehouse
Git fetch remote repository name
------- The branch obtained after fetch is named "warehouse name/branch name", but it is not jumped into this branch. In addition, you need to checkout to jump into this branch.
Capture remote repository content to local and merge
Git pull
Capture the branches of a remote Repository
Git checkout-B local branch name remote repository name/remote branch name
------ Note: "-B" indicates Branch before checkout, that is, obtain the remote branch to the local, and then jump into
Push to remote warehouse
Git push remote repository name local branch name: Remote branch name
---------- If the branch name is the same, you can write only one
---------- If it is not "Fast Forward", it will fail, because the remote repository may have content that is updated better than the local one.
---------- You can add "+" before the branch name to force push, but this will overwrite the new content in the remote repository.
Delete remote Branch
Git push origin: serverfix // The front of the colon is blank, which is equivalent to pushing a blank to the remote Branch
Show tags
Git tag
Git tag-l 'v1. 4. 2 .*'
Git tag-A v1.4-m' my version 1.4 '// Add a annotation tag
Start graphical interface
Git GUI // a graphical operation interface that provides basic operations
Gitk // repository browser. It's very important.