# git-status
> 原文: [https://git-scm.com/docs/git-status](https://git-scm.com/docs/git-status)
>
> 貢獻者:[honglyua](https://github.com/honglyua)
## 名稱
git-status - 顯示工作樹狀態
## 概要
```
git status [<options>…?] [--] [<pathspec>…?]
```
## 描述
顯示索引文件與當前HEAD提交之間存在差異的路徑,工作樹與索引文件之間存在差異的路徑,以及工作樹中未由Git跟蹤的路徑(和不會被[gitignore[5]](https://git-scm.com/docs/gitignore)忽略的路徑 )。第一個顯示的是你 _將_ 通過運行`git commit`提交的內容;第二個和第三個顯示的是你在運行`git commit`之前運行 _git add_ 來提交的內容。
## 選項
```
-s
```
```
--short
```
以短格式輸出。
```
-b
```
```
--branch
```
顯示分支和跟蹤信息,即使是在短格式下。
```
--show-stash
```
顯示當前隱藏的條目數。
```
--porcelain[=<version>]
```
以易于解析的格式為腳本提供輸出。這類似于短輸出,但在Git版本中保持穩定,無論用戶配置如何。請參閱下文了解詳情。
version參數用于指定格式版本。這是可選的,默認為原始版本 _v1_ 格式。
```
--long
```
以長格式輸出。這是默認值。
```
-v
```
```
--verbose
```
除了已更改的文件的名稱之外,還顯示要提交的文本更改(即,類似于`git diff --cached`的輸出)。如果指定`-v`兩次,則還顯示工作樹中尚未暫存的更改(即,類似于`git diff`的輸出)。
```
-u[<mode>]
```
```
--untracked-files[=<mode>]
```
顯示未跟蹤的文件。
mode參數用于指定未跟蹤文件的處理。它是可選的:它默認為 _all_,如果指定,它必須緊跟在選項上(例如`-uno`,但不是`-u no`)。
可能的選擇是:
* _no_ - 顯示沒有未跟蹤的文件。
* _normal_ - 顯示未跟蹤的文件和目錄。
* _all_ - 還顯示未跟蹤目錄中的單個文件。
如果未使用`-u`選項,則會顯示未跟蹤的文件和目錄(即與指定`normal`相同),以幫助您避免忘記添加新創建的文件。由于在文件系統中查找未跟蹤文件需要額外的工作,因此在大型工作樹中此模式可能需要一些時間。如果支持,請考慮啟用未跟蹤的緩存和拆分索引(請參閱`git update-index --untracked-cache`和`git update-index --split-index`),否則您可以使用`no`讓`git status`更快地返回,而不顯示未跟蹤的文件。
可以使用 [git-config [1]](https://git-scm.com/docs/git-config) 中記錄的status.showUntrackedFiles配置變量更改默認值。
```
--ignore-submodules[=<when>]
```
在查找更改時忽略對子模塊的更改。<when>可以是“none”,“untracked”,“dirty”或“all”,這些都是默認值。使用“none”時,如果子模塊包含未跟蹤或修改的文件,或者其HEAD與超級項目中記錄的提交不同,則可以使用“none”來修改子模塊,并可用于覆蓋[git-config [1]](https://git-scm.com/docs/git-config) 或 [gitmodules [5]](https://git-scm.com/docs/gitmodules)中都 _ignore_ 選項的任何設置。當使用“untracked”時,如果子模塊僅包含未跟蹤的內容(但仍會掃描修改的內容),則子模塊不會被視為dirty。使用“dirty”忽略對子模塊工作樹的所有更改,僅顯示存儲在超級項目中的提交的更改(這是1.7.0之前的行為)。使用“all”隱藏對子模塊的所有更改(并在設置配置選項`status.submoduleSummary`時禁止子模塊摘要的輸出)。
```
--ignored[=<mode>]
```
同時顯示被忽略的文件。
mode參數用于指定忽略文件的處理。它是可選的:它默認為 _traditional_。
可能的選擇是:
* _traditional_ - 顯示被忽略的文件和目錄,除非指定了--untracked-files = all,在這種情況下,將顯示被忽略目錄中的單個文件。
* _no_ - 顯示沒有被忽略的文件。
* _matching_ - 顯示與忽略模式匹配的被忽略的文件和目錄。
當指定 _matching_ 模式時,將顯示與忽略模式明確匹配的路徑。如果目錄與忽略模式匹配,則會顯示該目錄,但不會顯示忽略目錄中包含的路徑。如果目錄與忽略模式不匹配,但忽略了所有內容,則不顯示該目錄,但會顯示所有內容。
```
-z
```
用NUL而不是LF終止條目。如果沒有給出其他格式,這意味著`--porcelain=v1`輸出格式。
```
--column[=<options>]
```
```
--no-column
```
在列中顯示未跟蹤的文件。有關選項語法,請參閱配置變量column.status。沒有選項的`--column`和`--no-column`分別相當于 _always_ 和 _never_。
```
--ahead-behind
```
```
--no-ahead-behind
```
顯示或不顯示分支相對于其上游分支領先或落后多少節點數。默認為true。
```
--renames
```
```
--no-renames
```
無論用戶配置如何,都可以打開/關閉重命名檢測。另見 [git-diff [1]](https://git-scm.com/docs/git-diff) `--no-renames`。
```
--find-renames[=<n>]
```
打開重命名檢測,可選擇設置相似性閾值。另見 [git-diff [1]](https://git-scm.com/docs/git-diff) `--find-renames`。
```
<pathspec>…?
```
參見 [gitglossary [7]](https://git-scm.com/docs/gitglossary) 中的 _pathspec_ 條目。
## 輸出
此命令的輸出旨在用作提交模板注釋。默認的長格式設計很人性化,易讀,詳細和可描述性。其內容和輸出格式隨時可更改。
與許多其他Git命令不同,輸出中提到的路徑是相對于當前目錄的,如果您在子目錄中工作(這是故意的,以幫助剪切和粘貼)。請參閱下面的status.relativePaths配置選項。
### 短格式
在短格式中,每個路徑的狀態顯示為這些形式之一
```
XY PATH
XY ORIG_PATH -> PATH
```
其中`ORIG_PATH`是重命名/復制內容的來源。只有在重命名或復制條目時才會顯示`ORIG_PATH`。 `XY`是一個雙字母狀態代碼。
字段(包括`->`)通過單個空格彼此分開。如果文件名包含空格或其他不可打印的字符,則該字段將以C字符串文字的方式引用:由ASCII雙引號(34)字符包圍,并使用內部特殊字符反斜杠轉義。
對于具有合并沖突的路徑,`X`和`Y`顯示合并每一側的修改狀態。對于沒有合并沖突的路徑,`X`顯示索引的狀態,`Y`顯示工作樹的狀態。對于未跟蹤路徑,`XY`為`??`。其他狀態代碼可以解釋如下:
* '' =未經修改
* _M_ =修改
* _A_ =已添加
* _D_ =已刪除
* _R_ =重命名
* _C_ =復制
* _U_ =已更新但未合并
除非`--ignored`選項生效,否則不會列出忽略的文件,在這種情況下,`XY`為`!!`。
```
X Y Meaning
-------------------------------------------------
[AMD] 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
-------------------------------------------------
```
子模塊具有更多狀態,但是不報告M子模塊具有不同的HEAD,而是在子模塊已修改內容的索引中記錄?子模塊具有未跟蹤的文件,因為子模塊中的修改內容或未跟蹤文件無法通過超級項目中的`git add`添加以準備提交。
_m_ 和 _?_ 遞歸應用。例如,如果子模塊中的嵌套子模塊包含未跟蹤的文件,則報告為 _?_ 也是如此。
如果使用-b,則短格式狀態前面有一行
```
## branchname tracking info
```
### Porcelain格式版本1
版本1中porcelain格式類似于短格式,但保證不會在Git版本之間以向后兼容的方式或基于用戶配置進行更改。這使其成為腳本解析的理想選擇。上面簡短格式的描述也描述了porcelain格式,但有一些例外:
1. 用戶的color.status配置不受認可;顏色永遠都會關閉。
2. 用戶的status.relativePaths配置不受認可;顯示的路徑始終相對于存儲庫根目錄。
還有一種備用-z格式建議用于機器解析。在該格式中,狀態字段是相同的,但其他一些事情會發生變化。首先,-> 從重命名條目中省略, 并且字段順序被反轉(例如,_from ->_ 到變為 _from_)。其次,NUL(ASCII 0)跟在每個文件名后面,將空格替換為字段分隔符和終止換行符(但空格仍然將狀態字段與第一個文件名分開)。第三,包含特殊字符的文件名不是特殊格式的;不執行引用或反斜杠轉義。
任何子模塊更改都會報告為已修改`M`而不是`m`或單個`?`。
### Porcelain格式版本2
版本2格式添加了有關工作樹狀態和更改項目的更多詳細信息。版本2還定義了一組易于解析的可擴展可選標頭。
標題行以“#”開頭,??并添加以響應特定的命令行參數。解析器應該忽略它們無法識別的標頭。
### 分支標題
如果給出`--branch`,則打印一系列標題行,其中包含有關當前分支的信息。
```
Line Notes
------------------------------------------------------------
# branch.oid <commit> | (initial) Current commit.
# branch.head <branch> | (detached) Current branch.
# branch.upstream <upstream_branch> If upstream is set.
# branch.ab +<ahead> -<behind> If upstream is set and
the commit is present.
------------------------------------------------------------
```
### 跟蹤條目修改
在標題之后,為跟蹤的條目打印一系列行。可以根據變化的類型在三種不同線格式中的選擇一種來描述條目。跟蹤的條目以未定義的順序打印;解析器應允許以任何順序混合使用3種線型。
普通更改的條目具有以下格式:
```
1 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <path>
```
重命名或復制的條目具有以下格式:
```
2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path><sep><origPath>
```
```
Field Meaning
--------------------------------------------------------
<XY> A 2 character field containing the staged and
unstaged XY values described in the short format,
with unchanged indicated by a "." rather than
a space.
<sub> A 4 character field describing the submodule state.
"N..." when the entry is not a submodule.
"S<c><m><u>" when the entry is a submodule.
<c> is "C" if the commit changed; otherwise ".".
<m> is "M" if it has tracked changes; otherwise ".".
<u> is "U" if there are untracked changes; otherwise ".".
<mH> The octal file mode in HEAD.
<mI> The octal file mode in the index.
<mW> The octal file mode in the worktree.
<hH> The object name in HEAD.
<hI> The object name in the index.
<X><score> The rename or copy score (denoting the percentage
of similarity between the source and target of the
move or copy). For example "R100" or "C75".
<path> The pathname. In a renamed/copied entry, this
is the target path.
<sep> When the `-z` option is used, the 2 pathnames are separated
with a NUL (ASCII 0x00) byte; otherwise, a tab (ASCII 0x09)
byte separates them.
<origPath> The pathname in the commit at HEAD or in the index.
This is only present in a renamed/copied entry, and
tells where the renamed/copied contents came from.
--------------------------------------------------------
```
未合并的條目具有以下格式;第一個字符是“u”,用于區分普通的更改條目。
```
u <xy> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>
```
```
Field Meaning
--------------------------------------------------------
<XY> A 2 character field describing the conflict type
as described in the short format.
<sub> A 4 character field describing the submodule state
as described above.
<m1> The octal file mode in stage 1.
<m2> The octal file mode in stage 2.
<m3> The octal file mode in stage 3.
<mW> The octal file mode in the worktree.
<h1> The object name in stage 1.
<h2> The object name in stage 2.
<h3> The object name in stage 3.
<path> The pathname.
--------------------------------------------------------
```
### 其他項目
跟蹤條目(如果需要),將打印一系列未跟蹤的行,然后忽略在工作樹中找到的項目。
未跟蹤的項目具有以下格式:
```
? <path>
```
忽略的項目具有以下格式:
```
! <path>
```
### 路徑名格式注釋和-z
當給出`-z`選項時,路徑名按原樣打印,沒有任何引號,行以NUL(ASCII 0x00)字節終止。
如果沒有`-z`選項,則會引用具有“異常”字符的路徑名,如配置變量`core.quotePath`所述(參見 [git-config [1]](https://git-scm.com/docs/git-config) )。
## 配置
該命令符合`color.status`(或`status.color` - 它們的含義相同,后者保持向后兼容性)和`color.status.<slot>`配置變量以使其輸出著色。
如果config變量`status.relativePaths`設置為false,則顯示的所有路徑都相對于存儲庫根目錄,而不是當前目錄。
如果`status.submoduleSummary`設置為非零數字或為真(與-1或無限數字相同),則將為長格式啟用子模塊摘要,并顯示已修改子模塊的提交摘要(請參閱 [git-submodule [1]](https://git-scm.com/docs/git-submodule) 的--summary-limit選項)。請注意,當`diff.ignoreSubmodules`設置為 _all_ 時,或者僅對于那些`submodule.<name>.ignore=all`的子模塊,將禁止所有子模塊的status命令的摘要輸出。要查看被忽略的子模塊的摘要,您可以使用--ignore-submodules=dirty命令行選項或 _git submodule summary_ 命令,該命令顯示類似的輸出但不遵循這些設置。
## 后臺刷新
默認情況下,`git status`將自動刷新索引,從工作樹更新緩存的統計信息并寫出結果。寫出更新的索引是一種并非嚴格必要的優化(`status`計算自身的值,但將它們寫出來只是為了保證后續程序不重復的計算)。當`status`在后臺運行時,寫入期間保持的鎖定可能與其他同時的進程沖突,導致它們失敗。在后臺運行`status`的腳本應考慮使用`git --no-optional-locks status`(詳見 [git [1]](https://git-scm.com/docs/git) )。
## 也可以看看
[gitignore [5]](https://git-scm.com/docs/gitignore)
## GIT
部分 [git [1]](https://git-scm.com/docs/git) 套件
- git
- git-config
- git-help
- git-init
- git-clone
- git-add
- git-status
- git-diff
- git-commit
- git-reset
- git-rm
- git-mv
- git-branch
- git-checkout
- git-merge
- git-mergetool
- git-log
- git-stash
- git-tag
- git-worktree
- git-fetch
- git-pull
- git-push
- git-remote
- git-submodule
- git-show
- git-log
- git-shortlog
- git-describe
- git-apply
- git-cherry-pick
- git-rebase
- git-revert
- git-bisect
- git-blame
- git-grep
- gitattributes
- giteveryday
- gitglossary
- githooks
- gitignore
- gitmodules
- gitrevisions
- gittutorial
- gitworkflows
- git-am
- git-format-patch
- git-send-email
- git-request-pull
- git-svn
- git-fast-import
- git-clean
- git-gc
- git-fsck
- git-reflog
- git-filter-branch
- git-instaweb
- git-archive
- git-bundle
- git-daemon
- git-update-server-info
- git-cat-file
- git-check-ignore
- git-checkout-index
- git-commit-tree
- git-count-objects
- git-diff-index
- git-for-each-ref
- git-hash-object
- git-ls-files
- git-merge-base
- git-read-tree
- git-rev-list
- git-rev-parse
- git-show-ref
- git-symbolic-ref
- git-update-index
- git-update-ref
- git-verify-pack
- git-write-tree