Common statements

Git config --global user.name "XXX" git config --global user.email "[email protected]" git config --global user.email "[email protected] Git config --global color.status auto git config --global color.diff auto git config --global color.branch auto git config --global color.interactive auto git config --global Git + SSH ://[email protected]/ vt. git # clone git Git add xyz # add xyz file to index git add. # Add xyz file to index git add Amend -m 'XXX' git rm -m 'XXX' git rm -r * # Git log -n = n git log -n = n git log -n = n git log -n = n git log -n = n git log Dfb02e6e4f2f7b573337763e5c0013802e392818 # showed a submit details of the git show dfb02 # can only use commitid top git show HEAD # show HEAD commit log git Git tag -a v2.0 -m 'XXX' -m 'XXX' -m 'XXX' -m 'XXX Git diff # displays all changes that have not been added to the index. Git diff # displays all changes that have been added to the index but have not been committed Git diff HEAD^ # git diff HEAD^ # git diff origin/master... Git diff origin/master... Master --stat # show only different files, Git ://[email protected]/ vt. git Git branch -r # Git branch -r # git branch -r # git branch -r # git branch -r # git branch -r # Git branch -m master master_copy git branch -m master master_copy git branch -b Git checkout -b master master_copy # git checkout features/performance # Checkout the remote branch hotfixes/BJVEP933 and create a local trace branch git checkout v2.0 Git checkout -b devel origin/develop -b devel origin/develop Git cherry-pick ff44785404a8e # Git push origin :hotfixes/BJVEP933 # Delete hotfixes/BJVEP933 branch from remote repository Merge git mv README --prune # Merge git mv README --prune # Merge git mv README Git rebase git branch -d: reset the current version to HEAD (usually used for merge rollback Git branch D hotfixes/BJVEP933 # 全 部 部 hotfixes/BJVEP933 Git show-branch --all # show the history of all branches. Git whatchanged # show the history of all branches Git revert dfb02e6e4f2f7b573337763e5c0013802e392818 # to cancel the submit dfb02e6e4f2f7b573337763e5c0013802e392818 git ls - tree HEAD # Git rev-parse v2.0 Git reflog # Git show HEAD@{5} git show master@{yesterday} git log --pretty=format:'%h %s' --graph Git show HEAD~3 git show -s --pretty=raw 2be7fcb476 git stash # | | | | | | | | | | | | | | | | | | | | | | | Git grep -e '#define' --and -e SORT_DIRENT git gc git FSCKCopy the code

New: Create a new Git repository. The repository configuration, storage, and so on are stored in a Git folder

$git init [project-name] $git init [project-name] $git init [project-name] Running this command creates an empty directory named directory that contains only.git subdirectories. $git init --bare <directory> # Download a project and its entire code history # This command copies a repository to another directory and copies branches to the new repository. $git clone [url] $git clone [url]Copy the code

Configuration: Change the Settings. This can be a repository setting, system or global setting

$Git config -e [--global] $Git config --global user.email $Git config --global user.email $ git config --global user.name $ git config --global user.email "[email protected]" $ git config --global user.name "My Name" # defines the author email address used by the current user for all submissions. $git config --global alias.<alias-name> <git-command> $ git config --system core.editor <editor>Copy the code

Status: Shows the difference between the index file (that is, the current workspace) and the current header pointer to the commit

$git help status $git help status $git help status $git help status $git help statusCopy the code

Information: Get git information about certain files, branches, and commits

$git -s [keyword] $git -s [keyword] $git log [tag] HEAD --pretty=format:%s # $git log [tag] HEAD --grep feature # $git log --follow [file] $git whatchanged [file] $git log --follow [file] $git whatchanged [file --pretty --oneline # $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff $git diff HEAD # $git diff [first-branch]... $git diff [first-branch]... $git diff -- passage (staged) $git diff -- passage (staged) $git diff -- passage (staged) $git diff -- passage (staged) $git diff $git show [commit] $git show [commit] $git show [commit] $git show --name-only [commit] # $git br -r $git br <new_branch> $git br <new_branch> $git br <new_branch> $git br-merged $git br-merged $git br-merged $git br-merged $git br-merged $git br-merged $git br-merged $git br-mergedCopy the code

Add: Adds files to the current workspace. If you do not use Git Add to add files, they will not be added to subsequent commits

$git add /path/to/file/test.js $git add /path/to/file/test.js $git add add [file1] [file2] ... $git add -p $git add -p $git add -p $git add -p $git add -p $git add -pCopy the code

Delete: rm removes a file from the workspace, as opposed to the add command above

# remove the HelloWorld. Js $git rm HelloWorld. Js # remove files in the directory $git rm/pather/to/the/file/HelloWorld. Js # delete a workspace file, $git rm [file1] [file2]... $git rm --cached [file]Copy the code

Branch: Manages branches. You can run the following commands to add, delete, modify, check, and switch branches

# to check all the branches and remote $git branch - a # to create a new branch of $git branch [branch - the name] # # rename branch git branch -m < old name > < new name > $git branch - m $git branch $git branch $git branch $git branch $git branch $git branch $git branch $git branch $git branch [branch-name] $git branch [branch-name] $git branch [branch-name] Commit $git branch [branch] [commit] # commit $git branch [branch] # commit $git branch [branch] $git branch --track [branch] [remote-branch] $git checkout - $git checkout - $git checkout - $git checkout - $git checkout - $git checkout - $git checkout $git merge [branch] $git merge [branch] $git merge [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch] $git cherry-pick [branch [branch name] $git branch- Dr [remote/branch] $git co <branch> $git co-b <new_branch> $git co-b <new_branch> <branch> $git co-b <new_branch> <branch> $git co-b <new_branch> <branch> $git co-b <new_branch> <branch> $git co $id # $git br -d <branch> $git br -d <branch> $git br -d <branch>Copy the code

Check out: Updates the current workspace to the one identified by the index or to a specific workspace

$git checkout () $git checkout () $git checkout () $git checkout () $git checkout () < name >" $git checkout -b newBranchCopy the code

Remote synchronization: Remote branch of remote synchronization

$git fetch [remote] $git fetch [remote] $git fetch [remote] $git fetch [remote] $git fetch [remote] $git fetch [remote] $git remote add [shortname] [url] $git remote -v $git remote add origin git@ $git set-url origin git @github.com: $git set-url origin git @github.com: $git # git push < git push > < branch > # git push < branch $git push [remote] --force $git push [remote] --all $git push [remote] --all $git push [remote] --allCopy the code

Cancellation:

$git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit] $git checkout [commit $git reset [file] $git reset [file] $git reset [commit] $git reset [commit] $git reset [commit] $git reset --hard [commit] # reset current HEAD to commit, $git reset --keep [commit] # create a new commit to undo the specified commit # $git Revert HEAD $git Revert HEAD $git Revert HEAD $git stash stash pop $git stash list $git stash list $git stash apply $git stash dropCopy the code

Commit: The COMMIT saves changes to the current index as a new commit that includes changes and information made by the user

$git commit [file1] [file2] $git commit [file1] [file2] $git commit [file1] [file2] - m [message] # change after the workspace since the last commit, directly to the store block $git commit - a # displayed when all the diff information $git commit - v # using a new commit, $git commit --amend -m [message] $git commit --amend -m [message] $git commit --amend [file1] [file2]...Copy the code

Diff: Displays the difference between the current workspace and the submitted workspace

$git diff $git diff $git diff $git diff $git diff $git diffCopy the code

Grep: you can quickly search in the repository

Optional configuration: # Thanks to Travis Jeffery for the following usage: $git config --global grep. LineNumber $git config --global alias.g "grep --break $git grep 'variableName' -- '*. Java '$git grep 'variableName' -- '*. $git grep -e 'arrayListName' --and \(-e add -e remove \)Copy the code

Log: Displays all commits for this repository

$git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log -n $git log Diff $git log -p <file> diff $git log -p <file> diff $git log -p -2Copy the code

Merge is to merge external commits into its own branch

$git merge branchName $git merge branchName $git merge $git merge --no-ff branchNameCopy the code

Mv: Rename or move a file

$git mv test.js./new/path/test.js Renamed $git mv [file-original] [file-renamed] # renamed $git mv [file-original] [file-renamed] # renamed $git mv-f myFile existingFileCopy the code

tag:

$git tag = "git tag"; $git tag = "git tag" $git push [tag] $git push [tag] $git push [tag] $git push [tag] $git push [tag] $git checkout -b [branch] [tag] $git checkout -b [branch] [tag]Copy the code

Push: merge from the remote repository to the current branch

$git pull --no-ff $git pull --no-ff $git pull --no-ff $git pull --no-ffCopy the code

Ci:

$git ci <file> $git ci. $git ci -a $git ci -am "some comments" $git ci -a $git ci -am "some commentsCopy the code

Rebase (use with caution) : Apply all commit history on one branch to another. Do not use rebase on a remote branch that is already exposed.

$git rebase = $git rebase = $git rebase = $git rebase = $git rebase = $git rebase Reset the current header pointer to a specific state. This will enable you to undo merge, pull, commits, add. These are powerful commands, but be aware of the consequences. $git reset ($git reset) $git reset ($git reset) $git reset ($git reset) $git reset dha78as $git reset dha78as $git reset dha78as Overwrite the current working directory # and remove all uncommitted changes and commits after the specified commit. $git reset --hard dha78asCopy the code

Other:

$git archive $git apply.. $git apply --check.. $Git --version $Git --version $Git --versionCopy the code

Reference documents:

Commonly used Git command list: https://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html 📔 Linux, MySQL, Nginx, PHP, Git, Shell and other notes: https://github.com/guanguans/notesCopy the code

Public number: xiao He growth, The Buddha department more text, are their own once stepped on the pit or is learned

Interested partners welcome to pay attention to me, I am: He young life. Everybody progress duck together