[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 ```