首页·终端命令

git status

git

用法

git status [-sb] [-uall]

显示哪些已暂存、哪些改了、哪些还没被跟踪;未跟踪的文件默认只按文件夹折叠显示,要逐个看得加 -uall。

常用选项

选项含义
-sshort two-column format
-bshow the branch line, used as -sb
-ualllist untracked files one by one instead of folding folders
--ignoredalso list what .gitignore hides
-vappend the staged diff
--porcelainstable machine format for scripts

示例

git status -sb

one line per change plus the branch and its upstream

git status -uall

names every untracked file inside new folders

git status --porcelain

output a script can parse without surprises

难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. git status 是做什么的?

显示哪些已暂存、哪些改了、哪些还没被跟踪;未跟踪的文件默认只按文件夹折叠显示,要逐个看得加 -uall。

Q. 怎么写?

git status [-sb] [-uall] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 6 个,完整列表在 man git。这条命令属于git。

相关命令

man 手册: man git-status