Home Explore Blog CI



git

1st chunk of `Documentation/git-checkout-index.adoc`
7f09a30737bba106047b16f836e237d38ddc3eae14d9112b0000000100000b1a
git-checkout-index(1)
=====================

NAME
----
git-checkout-index - Copy files from the index to the working tree


SYNOPSIS
--------
[verse]
'git checkout-index' [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]
		   [--stage=<number>|all]
		   [--temp]
		   [--ignore-skip-worktree-bits]
		   [-z] [--stdin]
		   [--] [<file>...]

DESCRIPTION
-----------
Copies all listed files from the index to the working directory
(not overwriting existing files).

OPTIONS
-------
-u::
--index::
	update stat information for the checked out entries in
	the index file.

-q::
--quiet::
	be quiet if files exist or are not in the index

-f::
--force::
	forces overwrite of existing files

-a::
--all::
	checks out all files in the index except for those with the
	skip-worktree bit set (see `--ignore-skip-worktree-bits`).
	Cannot be used together with explicit filenames.

-n::
--no-create::
	Don'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>|all::
	Instead of checking out unmerged entries, copy out the
	files from the named stage.  <number> must be between 1 and 3.
	Note: --stage=all automatically implies --temp.

--temp::
	Instead of copying the files to the working directory,
	write the content to temporary files.  The temporary name
	associations will be written to stdout.

--ignore-skip-worktree-bits::
	Check out all files, including those with the skip-worktree bit
	set.

--stdin::
	Instead of taking a list of paths from the command line,
	read the list of paths from the standard input.  Paths are
	separated by LF (i.e. one path per line) by default.

-z::
	Only meaningful with `--stdin`; paths are separated with
	NUL character instead of LF.

\--::
	Do not interpret any more arguments as options.

The order of the flags used to matter, but not anymore.

Just doing `git checkout-index` does nothing. You probably meant
`git checkout-index -a`. And if you want to force it, you want
`git checkout-index -f -a`.

Intuitiveness is not the goal here. Repeatability is. The reason for
the "no arguments means no work" behavior is that from scripts you are
supposed to be able to do:

----------------
$ find . -name '*.h' -print0 | xargs -0 git checkout-index -f --
----------------

which will force all existing `*.h` files to be replaced with their
cached copies. If an empty command line implied "all", then this would
force-refresh everything in the index, which was not the point.  But
since 'git checkout-index' accepts --stdin it would be faster to use:

----------------
$ find . -name '*.h' -print0 | git checkout-index -f -z --stdin
----------------

The `--` is just a good idea when you know the rest will be filenames;
it will prevent problems with a filename of, for example,

Title: Git Checkout Index Command
Summary
The git-checkout-index command copies files from the Git index to the working tree, with various options for handling existing files, file lists, and staging. It allows for forcing overwrites, quiet operation, and checking out all files or specific ones, making it a flexible tool for managing Git repositories and working directories.