開發輔助

Git 速查表 - 常用命令快速參考

免費線上 Git 速查表,按分類整理的可搜尋命令參考。快速查詢分支、合併、變基、暫存、重置等 Git 命令。

免費使用 無需註冊 在瀏覽器中執行

工具工作區

Setup & Config

git init

Initialize a new Git repository in the current directory

--bare
git clone <url>

Clone a remote repository to your local machine

--depth 1--branch <name>--recurse-submodules
git config user.name "<name>"

Set the author name for commits

--global--local--list
git config user.email "<email>"

Set the author email for commits

--global--local

Staging & Commits

git add <file>

Stage a file for the next commit

-A-p.
git commit -m "<message>"

Create a commit with a message

--amend--no-edit-a--allow-empty
git status

Show the working tree status

-s--short
git diff

Show unstaged changes

--staged--cached--stat--name-only
git log

Show commit history

--oneline--graph--all-n <number>--author=<name>

Branching & Merging

git branch

List, create, or delete branches

-a-d <branch>-D <branch>-m <new-name>
git checkout <branch>

Switch to a branch or restore files

-b <new-branch>--
git switch <branch>

Switch to a branch (modern alternative to checkout)

-c <new-branch>--detach
git merge <branch>

Merge a branch into the current branch

--no-ff--squash--abort
git rebase <branch>

Reapply commits on top of another branch

-i--onto--abort--continue

Remote

git remote -v

List remote repositories with URLs

add <name> <url>remove <name>rename <old> <new>
git fetch

Download objects and refs from a remote

--all--prune<remote>
git pull

Fetch and integrate changes from a remote branch

--rebase--no-rebase<remote> <branch>
git push

Upload local commits to a remote repository

-u origin <branch>--force--tags--delete <branch>

Stash

git stash

Temporarily save uncommitted changes

-u--include-untracked-m "<message>"
git stash pop

Apply the most recent stash and remove it from the list

git stash list

List all stashed changes

git stash drop

Remove a specific stash entry

stash@{n}
git stash apply

Apply a stash without removing it from the list

stash@{n}

Undo & Reset

git reset <file>

Unstage a file while preserving changes

--soft HEAD~1--mixed HEAD~1--hard HEAD~1
git revert <commit>

Create a new commit that undoes a previous commit

--no-commit-n
git restore <file>

Discard changes in the working directory

--staged--source=<commit>
git clean -fd

Remove untracked files and directories

-n (dry run)-x-i

Inspection

git log --oneline

Show compact commit history (one line per commit)

git log --graph --all

Visualize branch history as a graph

git show <commit>

Display details and diff of a specific commit

git blame <file>

Show who last modified each line of a file

git reflog

Show a log of all reference updates (useful for recovery)

git shortlog -sn

Summarize commit counts by author

Tags

git tag <name>

Create a lightweight tag at the current commit

git tag -a <name> -m "<msg>"

Create an annotated tag with a message

git tag -l

List all tags

"v1.*"
git push origin <tag>

Push a specific tag to a remote

--tags
git tag -d <name>

Delete a local tag

什麼是 Git 速查表?

Git 速查表是一份按分類整理的常用 Git 命令快速參考指南。Git 是全球最流行的分散式版本控制系統,被數百萬開發者用於跟蹤變更、協作開發和管理專案歷史。面對數十個命令和數百個選項,即使是經驗豐富的開發者也需要一份簡潔的參考。本速查表涵蓋了從基本設定和暫存到互動式變基、儲存管理和歷史檢查等高階工作流程。

如何使用 Git 速查表

  1. 1瀏覽按分類整理的命令:設定、暫存、分支、遠端、儲藏、撤銷、檢查和標籤。
  2. 2使用搜尋框按關鍵詞過濾命令——輸入 'rebase'、 'stash'、 'reset' 或命令和描述的任何部分。
  3. 3每個命令顯示語法、簡短描述和常用標誌或選項。
  4. 4點選任意命令旁邊的複製按鈕,將其複製到剪貼簿以便在終端中使用。
  5. 5使用每個命令下方列出的標誌來發現你可能不知道的有用變體。

常見使用場景

日常開發工作流

在日常開發工作流中快速查詢提交、分支和推送程式碼的命令,無需離開瀏覽器。

學習 Git

Git 新手?瀏覽有組織的分類來發現命令並瞭解每個命令的作用,包括常用標誌和選項。

解決合併衝突

在需要解決衝突或撤銷錯誤時,找到正確的變基、合併、重置和還原命令。

程式碼審查與檢查

使用 git log、git blame 和 git show 等檢查命令來審查提交歷史、理解變更並追蹤程式碼作者。

常見問題

git merge 和 git rebase 有什麼區別?

兩者都將一個分支的更改整合到另一個分支。'git merge' 建立一個合併提交,保留兩個分支的完整歷史。'git rebase' 將你的提交重新應用在目標分支之上,產生線性歷史。Merge 對共享分支更安全;rebase 在合併前用於功能分支更乾淨。

如何撤銷最後一次提交?

使用 'git reset --soft HEAD~1' 撤銷提交但保留暫存的更改。使用 'git reset --mixed HEAD~1' 撤銷提交併取消暫存。使用 'git reset --hard HEAD~1' 撤銷提交併丟棄所有更改。如果提交已推送,請使用 'git revert' 建立安全的撤銷提交。

git fetch 和 git pull 有什麼區別?

'git fetch' 從遠端倉庫下載新資料但不將其整合到工作分支。'git pull' 本質上是 'git fetch' 加 'git merge'——它獲取並立即整合更改。當你想在合併前審查更改時使用 fetch。

支援哪些輸入格式與使用限制?

請依頁面上的欄位、範例值和接受格式準備輸入。若內容很大、格式不完整,或超出瀏覽器可處理的記憶體與效能範圍,工具可能需要更久才能完成;在複製、下載或貼回專案前,請先確認輸出符合你的目標系統要求。

資料會離開我的裝置嗎?

不會。此工具會直接在你的瀏覽器中處理輸入內容,不需要把資料上傳到我們的伺服器。若你要處理敏感資訊,仍建議在複製、下載或分享前先自行確認內容。