git status 簡單說明
基本用法:
-
顯示 Git 專案目前的狀態,包括:
- 工作區 (workspace) 中被修改但未加入暫存區的檔案。
- 暫存區 (staging) 中已加入但尚未提交的檔案。
- 是否有尚未追蹤的檔案 (untracked files)。
- 當前所在的 分支。
- 是否有尚未推送 (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過)。
常用情境:
- 查看目前有哪些檔案被修改了?
- 哪些檔案已經
git add進去等待提交? - 是否有遺漏的檔案需要追蹤?
搭配使用:
- 查看變更細節:
- 加入檔案到暫存區:
- 從暫存區移除:
git status 是 Git 使用中最常用的指令,隨時檢查當前狀態,避免遺漏和錯誤!😊