GIT-RESTORE(1)
β¨ GIT-RESTORE(1) β¨
okay bestie, welcome to git-restore β the actual icon of getting your files back π
she's part of the <rainbow>git</rainbow> manual-page family and honestly she deserves main character energy.
π NAME π
git-restore β restore working tree files π«Ά like, put your files back the way they were, no cap.
π¦ SYNOPSIS π¦
git restore [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>...
git restore [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul]
git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...]
π DESCRIPTION π
So basically: you point her at some paths in your working tree, and she restores them using contents from a restore source. Obsessed. But lowkey important β if a path is tracked but doesn't exist in the restore source, it gets removed so everything matches the source. β¨ bye bestie β¨
She's also flexible like that: you can restore the content in the index with --staged, or restore both the working tree and the index with --staged --worktree. Two locations, one queen π
By default: if --staged is given, contents are restored from HEAD; otherwise they come from the index. Wanna restore from a different commit? Say less β use --source.
heads up π«Ά for the differences between these three commands, go read "Reset, restore and revert" in git(1).
π OPTIONS π
-s <tree>,--source=<tree>β restore the working tree files with the content from the given tree. It's super common to name the source tree by naming a commit, branch or tag associated with it. If you don't specify it, contents are restored fromHEADif--stagedis given, otherwise from the index. Special case alert π¨ you may use<rev-A>...<rev-B>as a shortcut for the merge base of<rev-A>and<rev-B>β but only if there's exactly one merge base. You can leave out at most one of<rev-A>and<rev-B>, in which case it defaults toHEAD.-p,--patchβ interactively select hunks in the difference between the restore source and the restore location. To learn how to operate--patchmode, see the "Interactive Mode" section ofgit-add(1). it's giving choose-your-own-adventure π«-U<n>,--unified=<n>β generate diffs with<n>lines of context. The number of context lines defaults todiff.contextor3if the configuration variable is unset. (and-Uwithout<n>is silently accepted as a synonym for-pdue to a historical accident π iconic mess, we don't question it)--inter-hunk-context=<n>β show the context between diff hunks, up to the specified<number>of lines, thereby fusing hunks that are close to each other. Defaults todiff.interHunkContextor0if the config option is unset. fusion dance π§-W,--worktree,-S,--stagedβ specify the restore location. If neither option is specified, by default the working tree is restored. Specifying--stagedwill only restore the index. Specifying both restores both. π-q,--quietβ quiet, suppress feedback messages. Implies--no-progress. shhh bestie is focusing π€«--progress,--no-progressβ progress status is reported on the standard error stream by default when it is attached to a terminal, unless--quietis specified. This flag enables progress reporting even if not attached to a terminal, regardless of--quiet. she will always tell you what she's doing, periodt π₯--ours,--theirsβ when restoring files in the working tree from the index, use stage#2(ours) or#3(theirs) for unmerged paths. This option cannot be used when checking out paths from a tree-ish (i.e. with the--sourceoption).
β οΈ warning β οΈ duringgit rebaseandgit pull --rebase, ours and theirs may appear swapped. See the explanation of the same options ingit-checkout(1)for details. yes this is confusing, no it's not your fault π
-m,--mergeβ when restoring files on the working tree from the index, recreate the conflicted merge in the unmerged paths. This option cannot be used when checking out paths from a tree-ish (i.e. with the--sourceoption).--conflict=<style>β the same as--mergeoption above, but changes the way the conflicting hunks are presented, overriding themerge.conflictStyleconfiguration variable. Possible values aremerge(default),diff3, andzdiff3. pick your aesthetic π--ignore-unmergedβ when restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither--ours,--theirs,--mergeor--conflictis specified. Unmerged paths on the working tree are left alone. minding her own business, we love that π¦--ignore-skip-worktree-bitsβ in sparse checkout mode, the default is to only update entries matched by<pathspec>and sparse patterns in$GIT_DIR/info/sparse-checkout. This option ignores the sparse patterns and unconditionally restores any files in<pathspec>. rules? never heard of her π--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 likegit-checkout(1), this will detachHEADof the submodule. π submodule said independent era--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. defaults to the strict one, ngl she has standards β¨--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 variablecore.quotePath(seegit-config(1)). See also--pathspec-file-nuland global--literal-pathspecs. π--pathspec-file-nulβ only meaningful with--pathspec-from-file. Pathspec elements are separated withNULcharacter and all other characters are taken literally (including newlines and quotes). zero vibes, literal vibes πΈ--β do not interpret any more arguments as options. the classic "everything after this is a file, bestie" divider π«Ά<pathspec>...β limits the paths affected by the operation. For more details, see the pathspec entry ingitglossary(7).
β EXAMPLES β
okay so picture this little sequence: it switches to the master branch, reverts the Makefile to two revisions back, deletes hello.c by mistake, and then gets it back from the index. tragic then iconic πβ‘οΈπ
$ git switch master
$ git restore --source master~2 Makefile (1)
$ rm -f hello.c
$ git restore hello.c (2)
- take a file out of another commit
- restore
hello.cfrom the index
Want to restore all the C source files to match the version in the index? easy:
$ git restore '*.c'
Note the quotes around *.c β the file hello.c will also be restored, even though it's 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). yes, that's the whole trick, iykyk π
To restore all files in the current directory:
$ git restore .
or to restore all working tree files with top pathspec magic (see gitglossary(7)):
$ git restore :/
To restore a file in the index to match the version in HEAD (this is the same as using 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 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
cute and unreadable, the duality of woman π§ββοΈ
π SEE ALSO π
git-checkout(1), git-reset(1) β the rest of the trio, go say hi π«Ά
π GIT π
Part of the git(1) suite. obviously. queen of the whole suite π
and that's the page bestie π it's Git 2.56.0, dated 2026-09-27 β go forth and restore responsibly, mwah πβ¨
π¦ where this page comes from
- arch rolling: git 2.56.0-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms