IT系/リファレンス/Gitコマンド/git_checkout-index

Last-modified: 2020-06-02 (火) 00:41:23

git checkout-index

インデックスから作業ツリーにファイルをコピーするコマンド。

用例

  • 「/tmp/foo/」に管理対象外ファイルを除くGit管理ファイルを全てエクスポート
    git checkout-index -a --prefix=/tmp/foo/
  • 特定のコミット間で修正のあったファイルをエクスポート
    git diff コミットID..コミットID --name-only | git checkout-index --prefix=./xxxxdir/ --stdin

書式

git checkout-index [options]

公式によると以下の通り。

git checkout-index [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]
                   [--stage=<number>|all]
                   [--temp]
                   [-z] [--stdin]
                   [--] [<file>…]

options

-u | --indexupdate stat information for the checked out entries in the index file.
-q | --quietbe quiet if files exist or are not in the index
-f | --forceforces overwrite of existing files
-a | --allchecks out all files in the index. Cannot be used together with explicit filenames.
-n | --no-createDon’t checkout new files, only refresh files already checked out.
--prefix=<string>When creating files, prepend <string> (usually a directory including a trailing /)
--stage=<number>|allInstead of checking out unmerged entries, copy out the files from named stage. <number> must be between 1 and 3. Note: --stage=all automatically implies --temp.
--tempInstead of copying the files to the working directory write the content to temporary files. The temporary name associations will be written to stdout.
--stdinInstead of taking list of paths from the command line, read list of paths from the standard input. Paths are separated by LF (i.e. one path per line) by default.
-zOnly meaningful with --stdin; paths are separated with NUL character instead of LF.
--Do not interpret any more arguments as options.

説明

インデックスから作業ツリーにファイルをコピーするコマンド。
ブランチをまるごとexportしたい時、圧縮せずにディレクトリに出力する場合に使用できる。
圧縮してもよいなら、 git archive のほうが、 git checkout-index より挙動にクセがなく使いやすいとの意見がある。
(git checkout-index では出力先の指定で、--prefix=/tmp/foo/ のように指定するが最後の/を忘れるとfooがファイル名とくっついてしまう等)

関連

参考リンク

その他メモ

なにかあれば。