git commands, like a Linux command, are easy and quick to operate with commands. In general, the daily use just remember the following figure 6 commands, you can. But skilled use, I am afraid to remember 60~100 a command.
Here's a summary of common Git commands.
First of all, several special nouns are translated as follows:
Workspace: Work Area
Index/stage: Staging Area
Repository: Warehouse area (or local warehouse)
Remote: Repository One, new code base
# Create a new Git codebase in the current directory $ git init
# Create a new directory and initialize it to git code base $ git init [project-name]
# Download a project and its entire code history $ git clone [url]
Second, the configuration
The settings file for Git is. Gitconfig, which can be in the user's home directory (global configuration) or under the project directory (project configuration).
# show current git config $ git config--list
# edit git config file $ git config-e [--global]
# Set the user information when submitting code $ git config [--global] Use R.name "[Name]"
$ git config [--global] user.email "[Email address]"
third, add/delete files
# Add the specified file to staging area $ git add [file1] [file2] ...
# Add the specified directory to staging area, including subdirectories $ git add [dir]
# to add all files of the current directory to staging area $ git Add.
# before adding each change, will ask to confirm # for multiple changes to the same file, you can implement the sub-commit $ git add-p
# to 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 $ git rm--cached [file]
# Renaming 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]
# Submit Staging area specified file to warehouse area $ git commit [file1] [file2] ...-m [message]
# submit workspace since last Com Changes after MIT, direct to 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 last Commi T's commit information $ git commit--amend-m [message]
# redo the last commit and include a new change to the specified file $ git commit--amend [file1] [file2] ...
v. Branches
# List all local branches $ git branch
# list all remote branches $ git branch-r
# list all local branches and remote branch $ git branch-a
# Create a new branch, but still stay in the current branch $ git b Ranch [Branch-name]
# Create a new branch and switch to that branch $ git checkout-b [branch]
# Create a new branch, point to specify commit $ git branch [branch] [commit]
# Create a new branch, establish a trace relationship with the specified remote branch $ git branch--track [branch] [remote-branch]
# Switch to the specified branch and update the workspace $ git checkout [Branch-nam E]
# 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 branch $ git merge [branch]
# Select a commit, merge into the current branch $ git cherry-pick [commit]
# Delete branch $ git branch-d [branch -name]
# Remove remote branch $ Git push Origin--delete [Branch-name]
$ git branch-dr [remote/branch]
Six, label
# list all tag $ git tag
# Create a new tag at current commit $ git tag [tag]
# Create a new tag in the specified commit $ git tag [tag] [commit]
# Delete local tag $ git tag-d [tag]
# Delete remote tag $ git push origin:refs/tags/[tagname]
# view Tag info $ git show [tag]
# Commit specified tag $ git push [remote] [tag]
# Commit all tag $ git push [remote]--tags
# Create a new branch, point to a tag $ git checkout-b [branch] [tag]
Vii. Viewing information
# show changed files $ git status
# Displays the current branch version history $ git log
# shows commit history, and each commit changes the file $ git log--stat
# search commit history by keyword $ git log-s [keyword]
# shows all the changes after a commit, each of which occupies a single line of git log [tag] HEAD--pretty=format:%s
# shows all the after a commit Change, its "submission instructions" must match the search criteria $ git log [tag] HEAD--grep feature
# shows a file's version history, including file Rename $ git log--follow [file]
$ git whatch anged [File]
# Displays the specified file-related each time the diff $ git log-p [file]
# shows the last 5 commits in git log-5--pretty--oneline
# shows all submitted users, by Number of times sorted $ git shortlog-sn
# shows what the specified file is when the person modified the $ git blame [file]
# Display staging area and Workspace differences $ git diff
# Show staging area and previous Commi T difference $ git diff--cached [file]
# shows the difference between the workspace and the current branch of the latest commit $ git diff HEAD
# show two commits difference $ git diff [First-branch ]... [Second-branch]
# show how many lines of code you have written today $ git diff--shortstat "@{0 Day ago}"
# shows the metadata and content changes of a commit $ git show [commit]
# shows a file that has been changed by a commit $ git Show--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 synchronization
# Download all changes to the remote repository $ git fetch [remote]
# Show all remote warehouses $ 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 specified branch to remote warehouse $ g It 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]--al L
ix. Revocation
# Restore Staging area specified file to workspace $ git checkout [file]
# Restore a commit file to staging area and workspace $ git checkout [commit] [file]
# Recover staging Area All files into workspace $ git checkout.
# Reset Staging Area specified file, consistent with last commit, but workspace unchanged $ git reset [file]
# Reset Staging area with workspace, consistent with last commit $ git reset--hard
# Resets the current branch pointer To specify commit, reset staging area at the same time, but the workspace is unchanged $ git reset [commit]