Explanation:
- Workspace: local workspace
- Index:local staging area
- Repository:Local Warehouse
- Remote:a remote repository
new
# Create a Git repository in the current directory
$ git init
# Create a new directory, which is initialized to the Git repository
$ git init [project-name]
# Download a project and its entire code history
$ git clone [url]
Git configuration settings file .gitconfig, it can be in the user's home directory (global configuration) to be in the project directory (project configuration).
# Display the current configuration of Git
$ git config --list
# Edit Git profile
$ git config -e [--global]
# Set the user information submitted code of
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"
Add / delete files
# Adds the specified files to the staging area
$ git add [file1] [file2] ...
# Adds the specified directory to the staging area, including subdirectories
$ git add [dir]
# Add all the files in the current directory to the staging area
$ git add .
# Delete the workspace file, and will delete into the staging area
$ git rm [file1] [file2] ...
# Stop following the specified file, but the file will remain in the work area
$ git rm --cached [file]
# Rename files, and will be renamed into the staging area
$ git mv [file-original] [file-renamed]
Code Submit
# Submit to the staging area
$ git commit -m [message]
# Submit the file to the designated staging area
$ git commit [file1] [file2] ... -m [message]
# Change # submit the workspace since the last commit, directly to the warehouse area
$ git commit -a
# Diff displays all information submitted #
$ git commit -v
# Use a new commit, the alternative submission
# Submission of information # If the code does not commit any new changes, it is used on the override
$ git commit --amend -m [message]
# Redo the last commit, and includes a new variation of the specified file
$ git commit --amend [file1] [file2] ...
Branch
# List all local branches
$ git branch
# List all remote branch
$ git branch -r
# List all local branches and remote branch
$ git branch -a
# Create a new branch, but still remain in the current branch
$ git branch [branch-name]
# Create a branch and switch to that branch
$ git checkout -b [branch]
# Create a branch to the specified commit
$ git branch [branch] [commit]
# Create a branch with a specific remote tracking branch to establish relations
$ git branch --track [branch] [remote-branch]
# Switch to the specified branch and update workspace
$ git checkout [branch-name]
# Create a tracking relationship existing with the designated branch between remote branch
$ git branch --set-upstream [branch] [remote-branch]
# Consolidates branch to the current branch
$ git merge [branch]
# Choose a commit, merge into the current branch
$ git cherry-pick [commit]
# Remove branches #
$ git branch -d [branch-name]
# Delete remote branch
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
label
# List all tag
$ git tag
# Create a tag in the current commit
$ git tag [tag]
# Create a tag in the specified commit
$ git tag [tag] [commit]
# View tag information
$ git show [tag]
# Submit the specified tag
$ git push [remote] [tag]
# Commit all tag
$ git push [remote] --tags
# Create a branch, pointing to a tag
$ git checkout -b [branch] [tag]
View the information
# Display files with change
$ git status
# Display the current version of the history of the branch
$ git log
# Display commit history, and every time a file is changed commit
$ git log --stat
# Display the version history of a file, including file renamed
$ git log --follow [file]
$ git whatchanged [file]
# Display the document every time diff
$ git log -p [file]
# Display the file is what people at what time modified
$ git blame [file]
# Show differences staging area and work area
$ git diff
# Show Differences on a temporary storage area and commit the
$ git diff --cached [file]
# Shows the difference with the current work area between the branches of the latest commit
$ git diff HEAD
# Shows the difference between the two commits
$ git diff [first-branch]...[second-branch]
# Display metadata in a commit and content changes
$ git show [commit]
# Display a commit file changes
$ git show --name-only [commit]
# Displayed when a commit, the contents of a file
$ git show [commit]:[filename]
# Display the current branch recent submission
$ git reflog
Revocation
# Restore temporary area specified file to the workspace
$ git checkout [file]
# Commit restore a file to a specified workspace
$ git checkout [commit] [file]
# Restore all the files on a commit to the workspace
$ git checkout .
# Reset temporary area specified file, is consistent with the previous commit, but the same workspace
$ git reset [file]
# Reset the staging area and the work area, consistent with the previous commit
$ git reset --hard
# Reset the current branch pointer to the specified commit, at the same time to reset the staging area, but the same
$ git reset [commit]
# Reset the current branch HEAD specified commit, at the same time to reset the staging and work areas, consistent with the assigned commit
$ git reset --hard [commit]
# Reset the current HEAD to the specified commit, but remained unchanged staging and work areas
$ git reset --keep [commit]
# reate a new commit, commit to revoke the designation
# All changes will be # latter offset the former, and applied to the current branch
$ git revert [commit]
Remote synchronization
# Download all the remote repository changes
$ git fetch [remote]
# Display all the remote repository
$ git remote -v
# Display a remote repository information
$ git remote show [remote]
# Add a new remote repository, and named
$ git remote add [shortname] [url]
# Retrieve change the remote repository, and combined with the local branch
$ git pull [remote] [branch]
# Upload a local branch to the specified remote repository
$ git push [remote] [branch]
# Forcibly push the current branch to a remote repository, even if there is a conflict
$ git push [remote] --force
# Remote repository to push all branches
$ git push [remote] --all
# Generate a compressed package for release
$ git archive