当执行 git status
的时候,返回结果大致可分为3个部分:
如果在 git status
命令后面加上 --ignored
选项,还会列出被忽略的文件。
例如:
$ git status --ignored
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working\
directory)
Untracked files:
(use "git add <file>..." to include in what will be committed)
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
还有一种简洁的输出格式,即添加 --short
选项,例如
$ git status --short
D apple.c
M hello.c
A world.c
AD world_bak.c
?? 123.txt
git status --short
也可以简单写成 git status -s
。
这种输出每一行的格式是
XY PATH1 -> PATH2
PATH1
表示最近一次提交的文件, -> PATH2
表示索引或工作目录中文件,当文件路径改变时才会有 -> PATH2
这一项。
X
和Y
都是状态码,X
表示暂存区和最近一次提交的差异,Y
表示工作目录和暂存区的差异。
其含义是:
默认不会列出被忽略的文件,除非使用 --ignored
选项。
X
和Y
可能的组合如下表(方括号里面的可以没有):
X Y Meaning
-------------------------------------------------
not updated
M [ MD] updated in index
A [ MD] added to index
D deleted from index
R [ MD] renamed in index
C [ MD] copied in index
[MARC] index and work tree matches
[ MARC] M work tree changed since index
[ MARC] D deleted in work tree
[ D] R renamed in work tree
[ D] C copied in work tree
-------------------------------------------------
D D unmerged, both deleted
A U unmerged, added by us
U D unmerged, deleted by them
U A unmerged, added by them
D U unmerged, deleted by us
A A unmerged, both added
U U unmerged, both modified
-------------------------------------------------
? ? untracked
! ! ignored
-------------------------------------------------
参考资料
【1】https://git-scm.com/docs/git-status
【2】《Git 高手之路》,人民邮电出版社