Git 命令速查表

常用Git命令分類速查,涵蓋基礎操作、分支管理、遠端倉庫、撤銷回退等。完全免費、瀏覽器本機處理,不上傳伺服器。

Basic

git init— Initialize a new repository點選複製
git clone <url>— Clone a remote repository點選複製
git status— Show working tree status點選複製
git add <file>— Stage file(s) for commit點選複製
git add .— Stage all changes點選複製
git commit -m "msg"— Commit staged changes點選複製
git diff— Show unstaged changes點選複製
git diff --staged— Show staged changes點選複製

Branch

git branch— List 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 -v— List remote repositories點選複製
git remote add <name> <url>— Add a remote點選複製
git fetch— Fetch from remote點選複製
git pull— Fetch & merge點選複製
git push— Push 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~1— Undo last commit, keep staged點選複製
git reset --mixed HEAD~1— Undo last commit, keep unstaged點選複製
git reset --hard HEAD~1— Undo last commit, discard all點選複製
git revert <commit>— Create undo commit點選複製

Stash

git stash— Stash current changes點選複製
git stash list— List stashes點選複製
git stash pop— Apply & remove latest stash點選複製
git stash apply— Apply latest stash點選複製
git stash drop— Remove latest stash點選複製
git stash push -m "msg"— Stash with a message點選複製

Log

git log— Show commit history點選複製
git log --oneline— Compact commit history點選複製
git log --graph— Graph 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 tag— List 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 --tags— Push tags to remote點選複製