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