[TOC] #### 1. 前言 --- git status 命令用于查看當前 git 中的文件狀態 這個命令會將工作區、暫存區、版本庫中的文件狀態輸出到命令行界面 ``` git status ``` git status 命令是 git 中最常用的命令之一,當我們要執行命令操作時,一般都會先執行這個命令查看下當前狀態,因為只有當我們知道當前狀態是什么,才會清楚的知道,我們接下來應該怎么進行操作 #### 2. 各種狀態 --- 當版本庫中沒有提交記錄時,查看狀態會有以下提示 ``` # 還沒有提交記錄 No commits yet ``` 當沒有文件被修改或被刪除,也沒有未跟蹤的文件時 ``` # 沒有可以提交到版本庫的內容 (可以創建或拷貝文件,然后使用 "git add" 進行跟蹤) nothing to commit (create/copy files and use "git add" to track) ``` 當有未跟蹤的文件時 ``` # 未跟蹤的文件 Untracked files: # 使用 "git add" 命令將其添加到將要 commit 的內容中 (use "git add <file>..." to include in what will be committed) 1.txt # 暫存區中沒有內容,但存在未跟蹤的文件(使用 "git add" 進行跟蹤) nothing added to commit but untracked files present (use "git add" to track) ``` 一個新文件使用 git add 添加到暫存區后,查看狀態 ``` # 要提交的更改(其實就是將要提交到版本庫中的內容) Changes to be committed: # 使用 "git rm --cached <file>..." 取消暫存 (use "git rm --cached <file>..." to unstage) new file: 1.txt ``` 修改暫存區的文件或已提交到版本庫的文件后,查看狀態 ``` # 未提交的更改 Changes not staged for commit: # 使用 "git add <file>..." 更新將要 commit 的內容 (use "git add <file>..." to update what will be committed) # 使用 "git restore <file>..." 放棄工作目錄中的更改 (use "git restore <file>..." to discard changes in working directory) modified: 1.txt # 提交時未添加任何更改 (使用 "git add" 或 "git commit -a") 補充: 當暫存區中沒有內容時才會有該提示 no changes added to commit (use "git add" and/or "git commit -a") ``` 補充: 綠色字體代表是暫存區中的內容,紅色代表是工作區中的內容 ``` # 工作區(紅色): Untracked files Changes not staged for commit # 暫存區(綠色): Changes to be committed ``` #### 3. -s 參數 --- 可以使用 -s 參數來獲取簡短的輸出結果,常見的幾種狀態碼如下所示 | 狀態碼 | 描述 | | ------------ | ------------ | | A | 暫存區中新增的文件 | | D | 文件被刪除 | | M | 文件被更改 | | R | 文件被重命名 | | ?? | 工作區中未被跟蹤的文件 |  #### 4. `--ignored` 查看所有被忽略的文件 --- ``` git status --ignored ```