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點擊複製