Git 命令速查表

常用Git命令分类速查,涵盖基础操作、分支管理、远程仓库、撤销回退等。在线免费的Git命令速查表工具

Basic

git init— Initialize a new repository点击复制
git clone <url>— Clone a remote repository点击复制
git status— Show working tree status点击复制
git add <file>— Stage file(s) for commit点击复制
git add .— Stage all changes点击复制
git commit -m "msg"— Commit staged changes点击复制
git diff— Show unstaged changes点击复制
git diff --staged— Show staged changes点击复制

Branch

git branch— List local branches点击复制
git branch <name>— Create a new branch点击复制
git checkout <branch>— Switch to branch点击复制
git checkout -b <name>— Create & switch to branch点击复制
git switch <branch>— Switch to branch (new)点击复制
git switch -c <name>— Create & switch (new)点击复制
git merge <branch>— Merge branch into current点击复制
git branch -d <name>— Delete a branch点击复制
git branch -m <old> <new>— Rename a branch点击复制

Remote

git remote -v— List remote repositories点击复制
git remote add <name> <url>— Add a remote点击复制
git fetch— Fetch from remote点击复制
git pull— Fetch & merge点击复制
git push— Push to remote点击复制
git push -u origin <branch>— Push & set upstream点击复制
git remote remove <name>— Remove a remote点击复制

Undo/Reset

git reset HEAD <file>— Unstage a file点击复制
git checkout -- <file>— Discard working changes点击复制
git restore <file>— Discard working changes (new)点击复制
git reset --soft HEAD~1— Undo last commit, keep staged点击复制
git reset --mixed HEAD~1— Undo last commit, keep unstaged点击复制
git reset --hard HEAD~1— Undo last commit, discard all点击复制
git revert <commit>— Create undo commit点击复制

Stash

git stash— Stash current changes点击复制
git stash list— List stashes点击复制
git stash pop— Apply & remove latest stash点击复制
git stash apply— Apply latest stash点击复制
git stash drop— Remove latest stash点击复制
git stash push -m "msg"— Stash with a message点击复制

Log

git log— Show commit history点击复制
git log --oneline— Compact commit history点击复制
git log --graph— Graph of branches点击复制
git log -n <count>— Show last N commits点击复制
git show <commit>— Show commit details点击复制
git blame <file>— Line-by-line history点击复制

Tag

git tag— List tags点击复制
git tag <name>— Create lightweight tag点击复制
git tag -a <name> -m "msg"— Create annotated tag点击复制
git tag -d <name>— Delete a tag点击复制
git push origin --tags— Push tags to remote点击复制