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