1. 前言
2. 各种状态
3. -s 参数
4. --ignored 查看所有被忽略的文件

1. 前言


git status 命令用于查看当前 git 中的文件状态

这个命令会将工作区、暂存区、版本库中的文件状态输出到命令行界面

 
  1. git status

git status 命令是 git 中最常用的命令之一,当我们要执行命令操作时,一般都会先执行这个命令查看下当前状态,因为只有当我们知道当前状态是什么,才会清楚的知道,我们接下来应该怎么进行操作

2. 各种状态


当版本库中没有提交记录时,查看状态会有以下提示

 
  1. # 还没有提交记录
  2. No commits yet

当没有文件被修改或被删除,也没有未跟踪的文件时

 
  1. # 没有可以提交到版本库的内容 (可以创建或拷贝文件,然后使用 "git add" 进行跟踪)
  2. nothing to commit (create/copy files and use "git add" to track)

当有未跟踪的文件时

 
  1. # 未跟踪的文件
  2. Untracked files:
  3. # 使用 "git add" 命令将其添加到将要 commit 的内容中
  4. (use "git add <file>..." to include in what will be committed)
  5. 1.txt
  6. # 暂存区中没有内容,但存在未跟踪的文件(使用 "git add" 进行跟踪)
  7. nothing added to commit but untracked files present (use "git add" to track)

一个新文件使用 git add 添加到暂存区后,查看状态

 
  1. # 要提交的更改(其实就是将要提交到版本库中的内容)
  2. Changes to be committed:
  3. # 使用 "git rm --cached <file>..." 取消暂存
  4. (use "git rm --cached <file>..." to unstage)
  5. new file: 1.txt

修改暂存区的文件或已提交到版本库的文件后,查看状态

 
  1. # 未提交的更改
  2. Changes not staged for commit:
  3. # 使用 "git add <file>..." 更新将要 commit 的内容
  4. (use "git add <file>..." to update what will be committed)
  5. # 使用 "git restore <file>..." 放弃工作目录中的更改
  6. (use "git restore <file>..." to discard changes in working directory)
  7. modified: 1.txt
  8. # 提交时未添加任何更改 (使用 "git add" 或 "git commit -a") 补充: 当暂存区中没有内容时才会有该提示
  9. no changes added to commit (use "git add" and/or "git commit -a")

补充: 绿色字体代表是暂存区中的内容,红色代表是工作区中的内容

 
  1. # 工作区(红色):
  2. Untracked files
  3. Changes not staged for commit
  4. # 暂存区(绿色):
  5. Changes to be committed

3. -s 参数


可以使用 -s 参数来获取简短的输出结果,常见的几种状态码如下所示

状态码描述
A暂存区中新增的文件
D文件被删除
M文件被更改
R文件被重命名
??工作区中未被跟踪的文件

4. --ignored 查看所有被忽略的文件


 
  1. git status --ignored

 

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐