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