跳轉至

建立 2024-01-01 更新 2026-09-15

git status

git status 是最常用的指令:告訴你現在在哪條分支、哪些檔改了、哪些已暫存、有沒有還沒 push/pull 的提交。做任何 add、commit、merge 前後都看一眼,比較不容易漏檔或推錯。

基本用法

git status

它會顯示:

  1. 目前分支名稱。
  2. 與遠端追蹤分支是否同步。
  3. staging 裡已準備提交的檔。
  4. workspace 裡已修改但尚未 add 的檔。
  5. 從未追蹤的新檔(untracked)。

輸出範例

On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   index.html

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   style.css

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    newfile.js
  • On branch main:目前在 main。
  • Changes to be committed:已在 staging。
  • Changes not staged for commit:工作區有改、還沒 add。
  • Untracked files:Git 還沒開始追蹤。

常見搭配

git diff                 # 看尚未暫存的差異
git add <file>
git restore --staged <file>