# git-checkout-index
> 原文: [https://git-scm.com/docs/git-checkout-index](https://git-scm.com/docs/git-checkout-index)
## 名稱
git-checkout-index - 將文件從索引復制到工作樹
## 概要
```
git checkout-index [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]
[--stage=<number>|all]
[--temp]
[-z] [--stdin]
[--] [<file>…?]
```
## 描述
將索引中列出的所有文件復制到工作目錄(不覆蓋現有文件)。
## OPTIONS
```
-u
```
```
--index
```
更新索引文件中已簽出條目的統計信息。
```
-q
```
```
--quiet
```
如果文件存在或不在索引中,請保持安靜
```
-f
```
```
--force
```
強制覆蓋現有文件
```
-a
```
```
--all
```
檢出索引中的所有文件。不能與顯式文件名一起使用。
```
-n
```
```
--no-create
```
不要簽出新文件,只刷新已經簽出的文件。
```
--prefix=<string>
```
創建文件時,請添加< string> (通常是包含尾隨的目錄/)
```
--stage=<number>|all
```
不要檢出未合并的條目,而是從命名階段復制出文件。 <數>必須介于1和3之間。注意: - stage = all自動隱含--temp。
```
--temp
```
而不是將文件復制到工作目錄,而是將內容寫入臨時文件。臨時名稱關聯將寫入stdout。
```
--stdin
```
而不是從命令行獲取路徑列表,從標準輸入中讀取路徑列表。默認情況下,路徑由LF(即每行一個路徑)分隔。
```
-z
```
僅對`--stdin`有意義;路徑用NUL字符而不是LF分隔。
```
--
```
不要將任何更多的參數解釋為選項。
標志的順序過去很重要,但現在不再重要。
剛做`git checkout-index`什么也沒做。你可能意味著`git checkout-index -a`。如果你想強制它,你想要`git checkout-index -f -a`。
直覺不是這里的目標。重復性是。 “沒有參數意味著沒有工作”行為的原因是你應該能夠做到的腳本:
```
$ find . -name '*.h' -print0 | xargs -0 git checkout-index -f --
```
這將強制所有現有的`*.h`文件替換為其緩存副本。如果一個空命令行暗示“全部”,那么這將強制刷新索引中的所有內容,這不是重點。但是因為 _git checkout-index_ 接受--stdin它會更快使用:
```
$ find . -name '*.h' -print0 | git checkout-index -f -z --stdin
```
當你知道其余的是文件名時,`--`是個好主意。它可以防止文件名出現問題,例如`-a`。在腳本中使用`--`可能是一個很好的策略。
## 使用--temp或--stage = all
當使用`--temp`(或`--stage=all`暗示)_時,git checkout-index_ 將為每個要檢出的索引條目創建一個臨時文件。索引不會使用統計信息進行更新。如果調用者需要所有未合并條目的所有階段,以便外部合并工具可以處理未合并文件,則這些選項非常有用。
列表將寫入stdout,提供臨時文件名與跟蹤路徑名的關聯。列表格式有兩種變體:
1. tempname TAB路徑RS
第一種格式是省略`--stage`或不是`--stage=all`時使用的格式。字段tempname是保存文件內容的臨時文件名,path是索引中的跟蹤路徑名。僅輸出所請求的條目。
2. stage1temp SP stage2temp SP stage3tmp TAB路徑RS
第二種格式是`--stage=all`時使用的格式。如果索引中存在階段條目,則三階段臨時字段(stage1temp,stage2temp,stage3temp)列出臨時文件的名稱;如果沒有階段條目,則列出`.`。將始終從輸出中省略僅具有階段0條目的路徑。
在兩種格式中,RS(記錄分隔符)默認為換行符,但如果在命令行上傳遞-z,則為空字節。臨時文件名始終是安全字符串;它們永遠不會包含目錄分隔符或空格字符。 path字段始終相對于當前目錄,臨時文件名始終相對于頂級目錄。
如果要復制到臨時文件的對象是符號鏈接,則鏈接的內容將寫入普通文件。最終用戶或瓷器可以使用這些信息。
## 例子
```
To update and refresh only the files already checked out
```
```
$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
```
```
Using git checkout-index to "export an entire tree"
```
前綴能力基本上使得 _git checkout-index_ 用作“導出為樹”功能變得微不足道。只需將所需的樹讀入索引,然后執行:
```
$ git checkout-index --prefix=git-export-dir/ -a
```
`git checkout-index`將索引“導出”到指定目錄中。
最后的“/”很重要。導出的名稱實際上只是以指定的字符串為前綴。將此與下面的示例進行對比。
```
Export files with a prefix
```
```
$ git checkout-index --prefix=.merged- Makefile
```
這將檢出當前緩存的`Makefile`副本到文件`.merged-Makefile`中。
## 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