Guide |
Git is a free, open source distributed version control system for agile and efficient processing of any or small or large project. In general, you can use Git as long as you remember 6 commands. 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
First, create a new code base
Second, the configuration
The configuration file for Git is. Gitconfig, which can be in the user's home directory (global configuration) or under the project directory (project configuration).
# shows the current git configuration $ git config--list # edit git config file $ git config-e [--global] # Set user information when submitting code $ git config [--global] user.name"[Name]" $ git config [--global] user.email"[Email address]"
third, add/delete files
# Add specified file to staging area $ git add [file1] [file2] ... # Add the specified directory to staging area, including childCatalogue $ git add [dir] # Add all files of the current directory to the temporaryStorage Area $ git Add. # Delete the workspace file and set thisDelete into staging area $ git rm [file1] [file2] ... # Stop tracking the specified file, but the filewill remain in the workspace $ git RM--cached [file] # Rename the file, and put this nameinto staging Area $ git mv [file-original] [File-renaMed]
Iv. Code Submission
# Submit staging area to warehouse area $ git commit-m [message] # Submit the specified file of staging area to the warehouse area $ git commit [file1] [file2]-m [message] # Submit Workspace changes since the last commit, directly to the 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 commit information of the last commit $ git commit--amend-m [message] # Redo The last commit and include a new change to the specified file $ git commit--amend
v. Branches
# List all local branches $ git Branch # list all remote branches $ git branch-r # List all local 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 branch $ git checkout-b [branch] # Create a new branch, point to the specified commit $ git branch [branch] [commit] # Create a new branch to establish a tracking relationship with the specified remote branch $ git Branch--track [branch] [Remote-branch] # Switch to the specified branch and update the workspace $ git checkout [branch-name] # Establish a tracking relationship between the existing branch and the specified remote branch $ git Branch--set-upstream [branch] [Remote-branch] # Merge the specified branches into the current branch $ git merge [branch] # Select a commit to merge into the current branch $ git cherry-pick [commit] # Delete Branch $ git branch-d [branch-name] # Remove Remote Branch $ Git push origin--delete $ git branch-dr
Six, label
# List all tags $ git tag # Create a new tag in the current commit $ git tag [tag] # Create a new tag in the specified commit $ git tag [tag] [commit] # view tag Information $ git show [tag] # submit the specified tag $ git push [remote] [tag] # Submit All Tags $ git push [remote]--tags # Create a new branch, point to a tag $ git checkout-b [branch] [tag]
Vii. Viewing information
# Show files with changes $ git status # shows the version history of the current branch $ git log # shows the commit history, and the file that each commit changed $ git log--stat # Displays the version history of a file, including file renaming $ git log--follow [file] $ git whatchanged [file] # Displays each diff associated with the specified file $ git log-p [file] # shows who the specified file was and what time it was modified $ git blame [file] # Show Staging area and workspace differences $ git diff # shows the difference between staging area and the previous commit $ git diff--cached [] # shows the difference between the workspace and the latest commit of the current branch $ git diff HEAD # shows the difference between two commits $ git diff [first-branch] ... [Second-branch] # Show metadata and content changes for a commit $ git show [commit] # shows a file where a commit has changed $ git show--name-only [commit] # shows the last few commits 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 # Display information for a remote warehouse $ git remote show [remote] # Add a new remote repository and name $ git remote add [shortname] [url] # Retrieve changes to the remote repository and merge with the local branch $ git pull [remote] [branch] # Upload locally designated branch to remote repository $ git push [remote] [branch] # forcibly pushes the current branch to the remote repository, even if there is a conflict $ git push [remote]--force # Push all branches to the remote repository $ git push [remote]--all
ix. Revocation
# Restore Staging area specified file to workspace $ git checkout [file] # Restore a commit file to workspace $ git checkout [commit] [file] # Recover all files from last commit to workspace $ g It 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 the specified commit, same as Reset the staging area, but the workspace does not change the $ 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 refer to Commit, but keep staging area and workspace unchanged $ git reset--keep [commit] # Create a new commit to undo the specified commit # All changes to the latter will be offset by the former and applied to the current branch $ git revert [commit ]
Originally from: http://www.linuxprobe.com/git-common-commands.html
More Linux Dry Goods visit: http://www.linuxprobe.com/
Git common commands summary (super-practical)