Git 命令速查表
常用 Git 命令分类速查,涵盖基础操作、分支管理、远程仓库、撤销回退等。全程浏览器本地处理,不上传服务器。
Basic
git init— Initialize a new repositorygit clone <url>— Clone a remote repositorygit status— Show working tree statusgit add <file>— Stage file(s) for commitgit add .— Stage all changesgit commit -m "msg"— Commit staged changesgit diff— Show unstaged changesgit diff --staged— Show staged changesBranch
git branch— List local branchesgit branch <name>— Create a new branchgit checkout <branch>— Switch to branchgit checkout -b <name>— Create & switch to branchgit switch <branch>— Switch to branch (new)git switch -c <name>— Create & switch (new)git merge <branch>— Merge branch into currentgit branch -d <name>— Delete a branchgit branch -m <old> <new>— Rename a branchRemote
git remote -v— List remote repositoriesgit remote add <name> <url>— Add a remotegit fetch— Fetch from remotegit pull— Fetch & mergegit push— Push to remotegit push -u origin <branch>— Push & set upstreamgit remote remove <name>— Remove a remoteUndo/Reset
git reset HEAD <file>— Unstage a filegit checkout -- <file>— Discard working changesgit restore <file>— Discard working changes (new)git reset --soft HEAD~1— Undo last commit, keep stagedgit reset --mixed HEAD~1— Undo last commit, keep unstagedgit reset --hard HEAD~1— Undo last commit, discard allgit revert <commit>— Create undo commitStash
git stash— Stash current changesgit stash list— List stashesgit stash pop— Apply & remove latest stashgit stash apply— Apply latest stashgit stash drop— Remove latest stashgit stash push -m "msg"— Stash with a messageLog
git log— Show commit historygit log --oneline— Compact commit historygit log --graph— Graph of branchesgit log -n <count>— Show last N commitsgit show <commit>— Show commit detailsgit blame <file>— Line-by-line historyTag
git tag— List tagsgit tag <name>— Create lightweight taggit tag -a <name> -m "msg"— Create annotated taggit tag -d <name>— Delete a taggit push origin --tags— Push tags to remote