List of common Git commands

Generally speaking, as long as you remember the following 6 commands for daily use, it is ok. But proficient use, I am afraid to memorize 60 to 100 commands.

Ranking explain

Below is a list of the common Git commands I’ve compiled.

Workspace:

Workspace Index/Stage:

Temporary Repository:

Warehouse area (or local warehouse) Remote: Remote warehouse

Create a new code base

$Git init [url] $Git clone $Git init [url]Copy the code

Second, the configuration

Git’s setup file is.gitconfig, which can be in the user home directory (global configuration) or in the project directory (project configuration).

$Git config [--global] $Git config [--global] $Git config [--global "[name]" $git config [--global] user.email "[email address]" $git config --global color. UI true Status auto git config --global color.diff auto git config --global color.branch  auto git config --global color.interactive auto git config --global --unset http.proxy # remove proxy configuration on gitCopy the code

Add/delete files

$git add [file1] [file2]... $git add [dir] $git add. $git add. $git add -p $git rm [file1] [file2] $git mv [file-original] [file-renamed]Copy the code

4. Code submission

$git commit [file1] [file2] $git commit [file1] [file2] -m [message] # Commit workspace changes since last commit $git commit -v $git commit -am 'message' $git commit -- amend-m [message] # amend the last commit, $git commit --amend [file1] [file2]...Copy the code

Five, the branch

$git branch -r $git branch -r $git branch [branch-name] $git checkout -b [branch] Commit $git branch [branch] [commit] $git branch --track [branch] [remote-branch] $git checkout [branch-name] $git checkout - $git branch --set-upstream [branch] [remote-branch] $git merge [branch] $git cherry-pick [commit] $git branch -d [branch-name] # $git push origin --delete [branch-name] $git branch- Dr [remote/branch] $git branch- Dr [remote/branch Git checkout -b devel Origin /developCopy the code

Six, labels,

$git tag [tag] $git tag [commit] # Delete local tag $git tag $git show [tag] # $git push [remote] [tag] $git checkout -b [branch] [tag]Copy the code

7. Check information

$git log -- $git log -- $git log -- $git log -- $git log $git log -s [keyword] # $git log [tag] HEAD --pretty=format:%s # $git log [tag] HEAD --grep feature # --follow [file] $git whatchanged [file] # diff $git log -p [file --pretty --oneline # display all submitted users $git diff $git diff $git diff $git diff $git diff $git diff [first-branch] $git diff [first-branch] $git diff [first-branch] $git diff --shortstat "@{0 day ago}" $git show [commit] # $git show --name-only [commit] $git show [commit]:[filename] # $git reflogCopy the code

8. Remote synchronization

$git remote show [remote] $git remote show [remote] $git remote add [shortname] [url] $git pull [remote] [branch] $git push [remote] [branch] $git push [remote] --all $git push [remote] --allCopy the code

Nine, cancellation

$git checkout [commit] [file] $git checkout [file $git reset [file] $git reset [commit] # reset the HEAD of the current branch to commit. $git reset --hard [commit] # $git reset --keep [commit] # create a new commit to undo the specified commit $git Revert [commit] # Remove the uncommitted changes temporarily and move on to $git Stash $git Stash pop laterCopy the code

10 and other

Git config --global user.email --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 --unset http.proxy # remove proxy configuration on git git+ SSH ://[email protected]/VT Git add. # Add all the files in the current subdirectory to the index git commit -m 'XXX Git rm -r * # Git log -p -m git show git log -p -m git show 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 # git tag -a v2.0 -m 'XXX' # add v2.0 tag git show Git diff # display all changes that have not been added to index git diff --cached # Display all changes that have been added to index but have not yet been committed Git diff origin/master... git diff origin/master... Git diff origin/master... Master --stat # Git remote add origin git+ SSH ://[email protected]/VT Git branch -r # Display all merged branches git branch --merged # 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 # Git Checkout v2.0 -- Track hotfixes/BJVEP933 -- git Checkout v2.0 -- hotfixes/BJVEP933 Create a new branch devel from the remote branch develop and checkout git checkout -- README # Git cherry-pick ff44785404a8e # Git push origin :hotfixes/BJVEP933 # Git fetch -- delete hotfixes/BJVEP933 branch from remote repository Git pull origin master git mv README git mv README git mv README Git rebase git branch -d git rebase git branch -d Git branch -d hotfixes/BJVEP933 Git show-branch --all -- git whatchanged # Display the file changes corresponding to the commit history Git revert dfb02e6e4f2f7b573337763e5c0013802e392818 # to cancel the submit dfb02e6e4f2f7b573337763e5c0013802e392818 git ls - tree HEAD # Git rev-parse v2.0 Git reflog # SHA1 HASH git reflog Git log --pretty=format:'%h %s' --graph # Git show HEAD~3 git show -s --pretty=raw 2be7fcb476 git stash Stash stash list # stash stash show -p stash@{0} # stash stash apply stash@{0} # Git gc git FSCK # grep git git FSCK archiveCopy the code

Project recommendation:

Welcome to VX gongzhong – [more than programming]

More than 2000 GIGABytes of computer industry electronic resources sharing (constantly updated)

2020 micro channel small program full stack project miaomiaodating

Spring Boot development small and beautiful personal blog

Java Micro service combat 296 sets of large video – Grain mall

Java development micro service chang Buy mall actual combat [full 357 sets of large projects] – with code and courseware

The most complete and most detailed data structure and algorithm video