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