# git-fsck
> 原文: [https://git-scm.com/docs/git-fsck](https://git-scm.com/docs/git-fsck)
## 名稱
git-fsck - 驗證數據庫中對象的連通性和有效性
## 概要
```
git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
[--[no-]full] [--strict] [--verbose] [--lost-found]
[--[no-]dangling] [--[no-]progress] [--connectivity-only]
[--[no-]name-objects] [<object>*]
```
## 描述
驗證數據庫中對象的連接性和有效性。
## OPTIONS
```
<object>
```
作為不可達性痕跡的頭部對象的對象。
如果沒有給出對象, _git fsck_ 默認使用索引文件,`refs`命名空間中的所有SHA-1引用,以及所有reflog(除非給出--no-reflogs)作為頭。
```
--unreachable
```
打印出存在但無法從任何引用節點訪問的對象。
```
--[no-]dangling
```
打印存在但永遠不會_直接_使用的對象(默認)。 `--no-dangling`可用于從輸出中省略此信息。
```
--root
```
報告根節點。
```
--tags
```
報告標簽。
```
--cache
```
將索引中記錄的任何對象也視為不可達性跟蹤的頭節點。
```
--no-reflogs
```
不要認為僅由reflog中的條目引用的提交是可訪問的。此選項僅用于搜索曾經在ref中的提交,但現在不是,但仍在相應的reflog中。
```
--full
```
不僅檢查GIT_OBJECT_DIRECTORY($ GIT_DIR / objects)中的對象,還檢查在GIT_ALTERNATE_OBJECT_DIRECTORIES或$ GIT_DIR / objects / info / alternates中列出的備用對象池中找到的對象,以及在$ GIT_DIR / objects / pack中找到的打包Git存檔中找到的對象打包備用對象池中的子目錄。這是默認值;你可以用--no-full把它關掉。
```
--connectivity-only
```
僅檢查標記,提交和樹對象的連接。通過避免解壓縮blob,這會加速操作,但代價是丟失損壞的對象或其他有問題的問題。
```
--strict
```
啟用更嚴格的檢查,即捕獲由g + w位集記錄的文件模式,該模式由舊版本的Git創建。現有存儲庫(包括Linux內核,Git本身和稀疏存儲庫)具有觸發此檢查的舊對象,但建議使用此標志檢查新項目。
```
--verbose
```
說實話。
```
--lost-found
```
將懸空對象寫入.git / lost-found / commit /或.git / lost-found / other /,具體取決于類型。如果對象是blob,則將內容寫入文件,而不是其對象名稱。
```
--name-objects
```
當顯示可到達對象的名稱時,除了SHA-1之外還顯示描述**如何**可以到達的名稱,與 [git-rev-parse [1]](https://git-scm.com/docs/git-rev-parse) 兼容,例如`HEAD@{1234567890}~25^2:src/`。
```
--[no-]progress
```
除非指定了--no-progress或--verbose,否則默認情況下,當標準錯誤流附加到終端時,會報告進度狀態。 - 即使標準錯誤流未定向到終端, - progress也會強制進度狀態。
## 討論
git-fsck測試SHA-1和一般對象的健全性,它完全跟蹤產生的可達性和其他所有內容。它會打印出它找到的任何損壞(丟失或壞的對象),如果使用`--unreachable`標志,它還會打印出存在但無法從任何指定的頭節點(或默認集)訪問的對象,正如剛才提到的)。
您必須在備份或其他存檔中找到任何損壞的對象(即,您可以刪除它們并與其他某個站點一起執行 _rsync_ ,希望其他人擁有您已損壞的對象)。
如果core.commitGraph為true,則還將使用 _git commit-graph verify_ 檢查提交圖文件。參見 [git-commit-graph [1]](https://git-scm.com/docs/git-commit-graph) 。
## 提取的診斷
```
expect dangling commits - potential heads - due to lack of head information
```
您沒有指定任何節點作為頭,因此無法區分非父級提交和根節點。
```
missing sha1 directory <dir>
```
缺少包含sha1對象的目錄。
```
unreachable <type> <object>
```
< type>對象< object>,實際上并未在任何樹或提交的提交中直接或間接引用。這可能意味著您沒有指定另一個根節點或樹已損壞。如果您沒有錯過根節點,那么您也可以刪除無法訪問的節點,因為它們無法使用。
```
missing <type> <object>
```
< type>對象< object>,被引用但不存在于數據庫中。
```
dangling <type> <object>
```
< type>對象< object>,存在于數據庫中但從不直接使用。懸掛提交可以是根節點。
```
hash mismatch <object>
```
數據庫有一個對象,其哈希值與對象數據庫值不匹配。這表明存在嚴重的數據完整性問題。
## 環境變量
```
GIT_OBJECT_DIRECTORY
```
用于指定對象數據庫的根目錄(通常為$ GIT_DIR / objects)
```
GIT_INDEX_FILE
```
用于指定索引的索引文件
```
GIT_ALTERNATE_OBJECT_DIRECTORIES
```
用于指定其他對象數據庫根(通常未設置)
## 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