Git 命令速查表

常用 Git 命令分类速查,涵盖基础操作、分支管理、远程仓库、撤销回退等。 完全免费、免注册、浏览器本地处理,不上传服务器。

Basic

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

Branch

git branchList 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 -vList remote repositories点击复制
git remote add <name> <url>Add a remote点击复制
git fetchFetch from remote点击复制
git pullFetch & merge点击复制
git pushPush 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~1Undo last commit, keep staged点击复制
git reset --mixed HEAD~1Undo last commit, keep unstaged点击复制
git reset --hard HEAD~1Undo last commit, discard all点击复制
git revert <commit>Create undo commit点击复制

Stash

git stashStash current changes点击复制
git stash listList stashes点击复制
git stash popApply & remove latest stash点击复制
git stash applyApply latest stash点击复制
git stash dropRemove latest stash点击复制
git stash push -m "msg"Stash with a message点击复制

Log

git logShow commit history点击复制
git log --onelineCompact commit history点击复制
git log --graphGraph 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 tagList 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 --tagsPush tags to remote点击复制