Skip to content

git status 簡單說明

基本用法

git status
  • 顯示 Git 專案目前的狀態,包括:

    1. 工作區 (workspace) 中被修改但未加入暫存區的檔案。
    2. 暫存區 (staging) 中已加入但尚未提交的檔案。
    3. 是否有尚未追蹤的檔案 (untracked files)。
    4. 當前所在的 分支
    5. 是否有尚未推送 (push) 或拉取 (pull) 的更改。

輸出範例

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 中的檔案已準備好提交 (commit)。
  • Changes not staged for commit:表示 workspace 中的檔案已修改,但尚未加入 staging。
  • Untracked files:表示有尚未被 Git 追蹤的檔案 (從未 git add 過)。

常用情境

  1. 查看目前有哪些檔案被修改了?
  2. 哪些檔案已經 git add 進去等待提交?
  3. 是否有遺漏的檔案需要追蹤?

搭配使用

  • 查看變更細節
git diff
  • 加入檔案到暫存區
git add <file>
  • 從暫存區移除
git restore --staged <file>

git status 是 Git 使用中最常用的指令,隨時檢查當前狀態,避免遺漏和錯誤!😊