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点击复制