First, the new code base
# In the current directory to create a new Git repository
$ git the init
# Create a new directory, which is initialized to the Git repository
$ the init [Project-name] git
# downloading a project and its entire code history
$ git clone [url]
Second, the configuration
Git setup file .gitconfig
, it can (global configuration) in the user's home directory, you can also (project configuration) in the project directory.
# Display the current configuration Git
$ git config --list
# edit configuration files Git
$ git config -e [--global]
# Set the user information when submitting the code
$ git config [--global] user.name " [name] "
$ git config [--global] user.email" [Email address] "
Third, add / delete files
# Adds the specified files to the staging area
$ git the Add [file1] [file2] ...
# Adds the specified directory to the staging area, including subdirectories
$ git the Add [dir]
# Add all files in the current directory to the staging area
$ git add.
before # add each change, will require confirmation
# for many changes in the same file, can achieve sub commits
$ git the Add -p
# delete a workspace file and delete the staging area into
$ RM git [file1] [file2] ...
# stop tracking the specified file, but the file remains in the work area
$ git RM --cached [file]
# rename files, and will be renamed into the staging area
$ git mv [file-original] [file- renamed]
Fourth, submit the code
# Submitted to the staging area warehouse district
$ git the commit -m [the Message]
# temporary area specified file submitted to the warehouse district
$ git the commit [file1] [file2] ... -m [the Message]
# submitted from the work area after the change of times commit, directly to the warehouse district
$ git commit -a
display all diff information submitted #
$ git the commit -v
# using a new commit, commit the alternative
# If the code does not have any new changes, is used to rewrite the last time the information submitted commit
$ git commit -m --amend [the message]
# redo the last commit, and includes new changes specified file
$ git commit --amend [file1] [ file2] ...
V. branch
# 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 remain in the current branch
$ git branch [branch -name]
# create a branch and switch to the branch
$ git Checkout -b [branch]
# create a new branch, point to specify the commit
$ git branch [branch] [the commit]
# Create a branch, established to track the specified remote branch relations
$ git branch --track [branch] [Remote-branch]
# to switch to the designated branch, and update the work area
$ git Checkout [branch-name]
# switch to a branch
$ git Checkout -
# establish trace relationships in now between remote branches branched specified
$ Git branch the --set-upstream [branch] [remote-branch]
# merging branches to the current branch
$ Git merge [branch]
# selecting a commit, incorporated into the current branch
Cherry-Pick git $ [the commit]
# deleted branches
$ git Branch -d [Branch-name]
# delete remote branch
$ git the Push Origin --delete [Branch-name]
$ git Branch -dr [Remote / Branch]
Sixth, the label
# List all tag
$ git tag
# to create a new tag commit in the current
$ git tag [tag]
# Create a tag in the specified the commit
$ git tag [tag] [the commit]
# Delete the local tag
$ git tag -d [tag]
# delete remote tag
$ git the Push Origin: refs / Tags / [tagName]
# View information tag
$ git Show [tag]
# submit the specified tag
$ git the Push [remote] [tag]
# commit all tag
$ git the Push [remote] - Tags
# Create a new branch, points to a Tag
$ git Checkout -b [branch] [Tag]
Seven, view information
# Show documented changes
$ git Status
# show version of the history of the current branch
$ git log
# show commit history, and changed files each commit
$ git log --stat
# submit search history, according to keyword
$ git log - S [keyword]
# displays all changes after a commit, commit each occupy one line
$ git log [Tag] = the HEAD --pretty format:% S
# show all changes after a commit, which "commit" must match your search criteria
$ git log [Tag] the HEAD --grep the Feature
# show version history of a file, including file rename
$ git log --follow [file] $ git whatchanged [file]
# display the specified file every time diff
git log -p $ [file]
# show last 5 commits
$ git log -5 --pretty --oneline
# display all user submitted, sorted by number of commits
$ git shortlog -sn
# display the specified file is what people What time is modified
$ git blame [file]
# Show differences in the staging area and the work area
$ git diff
# display the staging area and on a difference commit
$ git diff --cached [File]
# displays the difference between the work area and the current branch newest commit
$ git diff the HEAD
# shows the difference between the two commits
$ git diff [First-Branch] ... [-SECOND, Branch]
# show today how many lines of code you write
$ git diff --shortstat "@ {0} ago Member Day"
# display metadata and content changes in a commit
$ git show [the commit]
# display file a commit changes
$ git show --name-only [the commit]
# display when a commit, the contents of a file
$ git show [the commit]: [filename]
# displays the current of recent submission branches
$ git reflog
Eight, remote synchronization
# Download remote repository of all changes
$ git FETCH [Remote]
# displays all remote repository
$ git Remote -v
# display information to a remote repository
$ git Remote Show [Remote]
# to add a new remote repository, and named
$ git the Add remote [the ShortName] [url]
# change to retrieve remote repository, and merge with the local branch
$ git pull [remote] [branch]
# Upload a local branch to a specified remote repository
$ git the push [remote] [branch]
# forcibly push current branch to a remote warehouse, even if there is a conflict
$ git the push [remote] --force
# push all the branches to the remote repository
$ git push [remote] --all
Nine, revocation
# Restore files to the staging area designated work area
$ git Checkout [File]
# restore a commit specified files to the staging area and a work area
$ git Checkout [commit] [File]
# restore all files to the staging area workspace
$ git Checkout.
# reset the staging area of the specified file, with the last commit consistent, but the work area unchanged
$ git the rESET [file]
# reset the staging area to the work area, and the last commit consistent
git the rESET --hard $
# reset the current branch pointer for the specified commit, at the same time to reset the staging area, but the work area unchanged
$ git the rESET [the commit]
# reset the current branch HEAD specified commit, while temporarily reset deposit and working areas, consistent with the specified commit
$ git the rESET --hard [commit]
# reset the current HEAD to the specified commit, but keep the staging area and working area unchanged
$ git the rESET --keep [commit]
# Create a commit, to revoke the designation commit
all changes # latter will be offset by the former, and applied to the current branch
$ git Revert [commit]
# uncommitted changes temporarily removed, then later moved
$ git stash $ git stash pop
X. Other
# Generate an alternative release archive
$ git archive
转自:<https://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html>