Home Explore Blog CI



git

3rd chunk of `Documentation/git-restore.adoc`
4f444c6fa8df678013b57f40845c6e6473dce9c9d05659730000000100000ce3
	`$GIT_DIR/info/sparse-checkout`. This option ignores the sparse
	patterns and unconditionally restores any files in
	_<pathspec>_.

`--recurse-submodules`::
`--no-recurse-submodules`::
	If _<pathspec>_ names an active submodule and the restore location
	includes the working tree, the submodule will only be updated if
	this option is given, in which case its working tree will be
	restored to the commit recorded in the superproject, and any local
	modifications overwritten. If nothing (or
	`--no-recurse-submodules`) is used, submodules working trees will
	not be updated. Just like linkgit:git-checkout[1], this will detach
	`HEAD` of the submodule.

`--overlay`::
`--no-overlay`::
	In overlay mode, never remove files when restoring. In no-overlay mode,
	remove tracked files that do not appear in the _<tree>_ of
	`--source=<tree>`, to make them match _<tree>_ exactly. The default
	is no-overlay mode.

`--pathspec-from-file=<file>`::
	Pathspec is passed in _<file>_ instead of commandline args. If
	_<file>_ is exactly `-` then standard input is used. Pathspec
	elements are separated by _LF_ or _CR_/_LF_. Pathspec elements can be
	quoted as explained for the configuration variable `core.quotePath`
	(see linkgit:git-config[1]). See also `--pathspec-file-nul` and
	global `--literal-pathspecs`.

`--pathspec-file-nul`::
	Only meaningful with `--pathspec-from-file`. Pathspec elements are
	separated with _NUL_ character and all other characters are taken
	literally (including newlines and quotes).

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

`<pathspec>...`::
	Limits the paths affected by the operation.
+
For more details, see the 'pathspec' entry in linkgit:gitglossary[7].

EXAMPLES
--------

The following sequence switches to the `master` branch, reverts the
`Makefile` to two revisions back, deletes `hello.c` by mistake, and gets
it back from the index.

------------
$ git switch master
$ git restore --source master~2 Makefile  <1>
$ rm -f hello.c
$ git restore hello.c                     <2>
------------

<1> take a file out of another commit
<2> restore `hello.c` from the index

If you want to restore _all_ C source files to match the version in
the index, you can say

------------
$ git restore '*.c'
------------

Note the quotes around `*.c`.  The file `hello.c` will also be
restored, even though it is no longer in the working tree, because the
file globbing is used to match entries in the index (not in the
working tree by the shell).

To restore all files in the current directory

------------
$ git restore .
------------

or to restore all working tree files with 'top' pathspec magic (see
linkgit:gitglossary[7])

------------
$ git restore :/
------------

To restore a file in the index to match the version in `HEAD` (this is
the same as using linkgit:git-reset[1])

------------
$ git restore --staged hello.c
------------

or you can restore both the index and the working tree (this is the same
as using linkgit:git-checkout[1])

------------
$ git restore --source=HEAD --staged --worktree hello.c
------------

or the short form which is more practical but less readable:

------------
$ git restore -s@ -SW hello.c
------------

SEE ALSO
--------
linkgit:git-checkout[1],
linkgit:git-reset[1]

GIT
---
Part of the linkgit:git[1] suite

Title: Git Restore Command Usage and Examples
Summary
The git restore command allows users to restore files from the index or other commits, with various options for customizing the restore process, including handling submodules, sparse checkouts, and file globbing, and is demonstrated through several example use cases.