CINXE.COM
Git - git-restore Documentation
<!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript"> const currentTheme = localStorage.getItem("theme") if (currentTheme) { const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches if ((prefersDarkScheme && currentTheme === "light") || (!prefersDarkScheme && currentTheme === "dark")) { document.documentElement.dataset.theme = currentTheme } } </script> <meta charset='utf-8'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Git - git-restore Documentation</title> <link href="/favicon.ico" rel='shortcut icon' type='image/x-icon'> <link rel="stylesheet" href="/application.min.css"> </head> <body id="documentation"> <div class="inner"> <header> <a id="logo" href="/"><img src="/images/logo@2x.png" width="110" height="46" alt="Git" class="no-filter" /></a> <span id="tagline"></span> <script type="text/javascript"> const taglines = [ "fast-version-control", "everything-is-local", "distributed-even-if-your-workflow-isnt", "local-branching-on-the-cheap", "distributed-is-the-new-centralized" ]; var tagline = taglines[Math.floor(Math.random() * taglines.length)]; document.getElementById('tagline').innerHTML = '--' + tagline; </script> <div id="search-container"> <form id="search" action="/search/results"> <input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" /> </form> <div id="search-results"></div> </div> <img src="/images/dark-mode.svg" id="dark-mode-button" /> </header> </div> <div class="inner"> <div id="content-wrapper"> <div tabindex="1" class="sidebar-btn"></div> <aside class="sidebar" id="sidebar"> <nav> <ul> <li> <a href="/about">About</a> <ul> </ul> </li> <li> <a href="/doc" class="active">Documentation</a> <ul class="expanded"> <li> <a href="/docs" class="active">Reference</a> </li> <li> <a href="/book">Book</a> </li> <li> <a href="/videos">Videos</a> </li> <li> <a href="/doc/ext">External Links</a> </li> </ul> </li> <li> <a href="/downloads">Downloads</a> <ul > <li> <a href="/downloads/guis">GUI Clients</a> </li> <li> <a href="/downloads/logos">Logos</a> </li> </ul> </li> <li> <a href="/community">Community</a> </li> </ul> </nav> </aside> <div id="content"> <div id='reference-version'> <a class="dropdown-trigger" id="reference-languages-trigger" data-panel-id="l10n-versions-dropdown" href="#"> English ▾</a> <div class='dropdown-panel right' id='l10n-versions-dropdown'> <header>Localized versions of <strong>git-restore</strong> manual</header> <ol class='reference-previous-versions'> <li> <a href="/docs/git-restore"><span class="version">English</span> </a> </li> <li> <a href="/docs/git-restore/de"><span class="version">Deutsch</span> </a> </li> <li> <a href="/docs/git-restore/fr"><span class="version">Français</span> </a> </li> <li> <a href="/docs/git-restore/pt_BR"><span class="version">Português (Brasil)</span> </a> </li> <li> <a href="/docs/git-restore/zh_HANS-CN"><span class="version">简体中文</span> </a> </li> </ol> <footer> Want to read in your language or fix typos?<br/> <a href="https://github.com/jnavila/git-manpages-l10n">You can help translate this page</a>. </footer> </div> <a class="dropdown-trigger" id="reference-topics-trigger" data-panel-id="topics-dropdown" href="#">Topics ▾</a> <div class='dropdown-panel right' id='topics-dropdown'> <div class='three-column'> <div class='column-left'> <h3 class='setup'>Setup and Config</h3> <ul class='unstyled'> <li> <a href="/docs/git"> git </a> </li> <li> <a href="/docs/git-config"> config </a> </li> <li> <a href="/docs/git-help"> help </a> </li> <li> <a href="/docs/git-bugreport"> bugreport </a> </li> <li> <a href="/doc/credential-helpers"> Credential helpers </a> </li> </ul> <h3 class='projects'>Getting and Creating Projects</h3> <ul class='unstyled'> <li> <a href="/docs/git-init"> init </a> </li> <li> <a href="/docs/git-clone"> clone </a> </li> </ul> <h3 class='snapshotting'>Basic Snapshotting</h3> <ul class='unstyled'> <li> <a href="/docs/git-add"> add </a> </li> <li> <a href="/docs/git-status"> status </a> </li> <li> <a href="/docs/git-diff"> diff </a> </li> <li> <a href="/docs/git-commit"> commit </a> </li> <li> <a href="/docs/git-notes"> notes </a> </li> <li> <a href="/docs/git-restore"> restore </a> </li> <li> <a href="/docs/git-reset"> reset </a> </li> <li> <a href="/docs/git-rm"> rm </a> </li> <li> <a href="/docs/git-mv"> mv </a> </li> </ul> <h3 class='branching'>Branching and Merging</h3> <ul class='unstyled'> <li> <a href="/docs/git-branch"> branch </a> </li> <li> <a href="/docs/git-checkout"> checkout </a> </li> <li> <a href="/docs/git-switch"> switch </a> </li> <li> <a href="/docs/git-merge"> merge </a> </li> <li> <a href="/docs/git-mergetool"> mergetool </a> </li> <li> <a href="/docs/git-log"> log </a> </li> <li> <a href="/docs/git-stash"> stash </a> </li> <li> <a href="/docs/git-tag"> tag </a> </li> <li> <a href="/docs/git-worktree"> worktree </a> </li> </ul> <h3 class='sharing'>Sharing and Updating Projects</h3> <ul class='unstyled'> <li> <a href="/docs/git-fetch"> fetch </a> </li> <li> <a href="/docs/git-pull"> pull </a> </li> <li> <a href="/docs/git-push"> push </a> </li> <li> <a href="/docs/git-remote"> remote </a> </li> <li> <a href="/docs/git-submodule"> submodule </a> </li> </ul> </div> <div class='column-middle'> <h3 class='inspection'>Inspection and Comparison</h3> <ul class='unstyled'> <li> <a href="/docs/git-show"> show </a> </li> <li> <a href="/docs/git-log"> log </a> </li> <li> <a href="/docs/git-diff"> diff </a> </li> <li> <a href="/docs/git-difftool"> difftool </a> </li> <li> <a href="/docs/git-range-diff"> range-diff </a> </li> <li> <a href="/docs/git-shortlog"> shortlog </a> </li> <li> <a href="/docs/git-describe"> describe </a> </li> </ul> <h3 class='patching'>Patching</h3> <ul class='unstyled'> <li> <a href="/docs/git-apply"> apply </a> </li> <li> <a href="/docs/git-cherry-pick"> cherry-pick </a> </li> <li> <a href="/docs/git-diff"> diff </a> </li> <li> <a href="/docs/git-rebase"> rebase </a> </li> <li> <a href="/docs/git-revert"> revert </a> </li> </ul> <h3 class='debugging'>Debugging</h3> <ul class='unstyled'> <li> <a href="/docs/git-bisect"> bisect </a> </li> <li> <a href="/docs/git-blame"> blame </a> </li> <li> <a href="/docs/git-grep"> grep </a> </li> </ul> <h3 class='email'>Email</h3> <ul class='unstyled'> <li> <a href="/docs/git-am"> am </a> </li> <li> <a href="/docs/git-apply"> apply </a> </li> <li> <a href="/docs/git-format-patch"> format-patch </a> </li> <li> <a href="/docs/git-send-email"> send-email </a> </li> <li> <a href="/docs/git-request-pull"> request-pull </a> </li> </ul> <h3 class='external'>External Systems</h3> <ul class='unstyled'> <li> <a href="/docs/git-svn"> svn </a> </li> <li> <a href="/docs/git-fast-import"> fast-import </a> </li> </ul> <h3 class='server-admin'>Server Admin</h3> <ul class='unstyled'> <li> <a href="/docs/git-daemon"> daemon </a> </li> <li> <a href="/docs/git-update-server-info"> update-server-info </a> </li> </ul> </div> <div class='column-right'> <h3 class='guides'>Guides</h3> <ul class='unstyled'> <li> <a href="/docs/gitattributes"> gitattributes </a> </li> <li> <a href="/docs/gitcli"> Command-line interface conventions </a> </li> <li> <a href="/docs/giteveryday"> Everyday Git </a> </li> <li> <a href="/docs/gitfaq"> Frequently Asked Questions (FAQ) </a> </li> <li> <a href="/docs/gitglossary"> Glossary </a> </li> <li> <a href="/docs/githooks"> Hooks </a> </li> <li> <a href="/docs/gitignore"> gitignore </a> </li> <li> <a href="/docs/gitmodules"> gitmodules </a> </li> <li> <a href="/docs/gitrevisions"> Revisions </a> </li> <li> <a href="/docs/gitsubmodules"> Submodules </a> </li> <li> <a href="/docs/gittutorial"> Tutorial </a> </li> <li> <a href="/docs/gitworkflows"> Workflows </a> </li> <li> <a href="/docs/git#_guides"> All guides... </a> </li> </ul> <h3 class='admin'>Administration</h3> <ul class='unstyled'> <li> <a href="/docs/git-clean"> clean </a> </li> <li> <a href="/docs/git-gc"> gc </a> </li> <li> <a href="/docs/git-fsck"> fsck </a> </li> <li> <a href="/docs/git-reflog"> reflog </a> </li> <li> <a href="/docs/git-filter-branch"> filter-branch </a> </li> <li> <a href="/docs/git-instaweb"> instaweb </a> </li> <li> <a href="/docs/git-archive"> archive </a> </li> <li> <a href="/docs/git-bundle"> bundle </a> </li> </ul> <h3 class='plumbing'>Plumbing Commands</h3> <ul class='unstyled'> <li> <a href="/docs/git-cat-file"> cat-file </a> </li> <li> <a href="/docs/git-check-ignore"> check-ignore </a> </li> <li> <a href="/docs/git-checkout-index"> checkout-index </a> </li> <li> <a href="/docs/git-commit-tree"> commit-tree </a> </li> <li> <a href="/docs/git-count-objects"> count-objects </a> </li> <li> <a href="/docs/git-diff-index"> diff-index </a> </li> <li> <a href="/docs/git-for-each-ref"> for-each-ref </a> </li> <li> <a href="/docs/git-hash-object"> hash-object </a> </li> <li> <a href="/docs/git-ls-files"> ls-files </a> </li> <li> <a href="/docs/git-ls-tree"> ls-tree </a> </li> <li> <a href="/docs/git-merge-base"> merge-base </a> </li> <li> <a href="/docs/git-read-tree"> read-tree </a> </li> <li> <a href="/docs/git-rev-list"> rev-list </a> </li> <li> <a href="/docs/git-rev-parse"> rev-parse </a> </li> <li> <a href="/docs/git-show-ref"> show-ref </a> </li> <li> <a href="/docs/git-symbolic-ref"> symbolic-ref </a> </li> <li> <a href="/docs/git-update-index"> update-index </a> </li> <li> <a href="/docs/git-update-ref"> update-ref </a> </li> <li> <a href="/docs/git-verify-pack"> verify-pack </a> </li> <li> <a href="/docs/git-write-tree"> write-tree </a> </li> </ul> </div> </div> </div> <a class="dropdown-trigger" id="reference-versions-trigger" data-panel-id="previous-versions-dropdown" href="#"> Latest version ▾ </a> <span class="light d-flex">git-restore last updated in 2.49.0</span> <div class='dropdown-panel left' id='previous-versions-dropdown'> <header>Changes in the <strong>git-restore</strong> manual</header> <ol class='reference-previous-versions'> <li> <a href="/docs/git-restore/2.49.0"><span class="version">2.49.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2025-03-14</em> </a> </li> <li class="no-change"><span>2.43.1 → 2.48.1 no changes</span></li> <li> <a href="/docs/git-restore/2.43.0"><span class="version">2.43.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2023-11-20</em> </a> </li> <li class="no-change"><span>2.35.1 → 2.42.4 no changes</span></li> <li> <a href="/docs/git-restore/2.35.0"><span class="version">2.35.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2022-01-24</em> </a> </li> <li class="no-change"><span>2.30.1 → 2.34.8 no changes</span></li> <li> <a href="/docs/git-restore/2.30.0"><span class="version">2.30.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2020-12-27</em> </a> </li> <li class="no-change"><span>2.27.1 → 2.29.3 no changes</span></li> <li> <a href="/docs/git-restore/2.27.0"><span class="version">2.27.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2020-06-01</em> </a> </li> <li class="no-change"><span>2.25.1 → 2.26.3 no changes</span></li> <li> <a href="/docs/git-restore/2.25.0"><span class="version">2.25.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2020-01-13</em> </a> </li> <li class="no-change"><span>2.23.1 → 2.24.4 no changes</span></li> <li> <a href="/docs/git-restore/2.23.0"><span class="version">2.23.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2019-08-16</em> </a> </li> <li> </li> </ol> <footer> <p>Check your version of git by running</p> <code class="command">git --version</code> </footer> </div> </div> <div id="main" data-pagefind-filter="category:reference" data-pagefind-meta="category:Reference" data-pagefind-weight="0.05" data-pagefind-body> <div class="sect1"> <h2 id="_name"><a class="anchor" href="#_name"></a>NAME</h2> <div class="sectionbody"> <div class="paragraph"> <p>git-restore - Restore working tree files</p> </div> </div> </div> <div class="sect1"> <h2 id="_synopsis"><a class="anchor" href="#_synopsis"></a>SYNOPSIS</h2> <div class="sectionbody"> <div class="paragraph"> <p>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>…​]</p> </div> </div> </div> <div class="sect1"> <h2 id="_description"><a class="anchor" href="#_description"></a>DESCRIPTION</h2> <div class="sectionbody"> <div class="paragraph"> <p>Restore specified paths in the working tree with some contents from a restore source. If a path is tracked but does not exist in the restore source, it will be removed to match the source.</p> </div> <div class="paragraph"> <p>The command can also be used to restore the content in the index with <code>--staged</code>, or restore both the working tree and the index with <code>--staged --worktree</code>.</p> </div> <div class="paragraph"> <p>By default, if <code>--staged</code> is given, the contents are restored from <code>HEAD</code>, otherwise from the index. Use <code>--source</code> to restore from a different commit.</p> </div> <div class="paragraph"> <p>See "Reset, restore and revert" in <a href='/docs/git'>git[1]</a> for the differences between the three commands.</p> </div> <div class="paragraph"> <p>THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.</p> </div> </div> </div> <div class="sect1"> <h2 id="_options"><a class="anchor" href="#_options"></a>OPTIONS</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-restore.txt-code-slttreegtcode"> <a class="anchor" href="#Documentation/git-restore.txt-code-slttreegtcode"></a><code>-s <tree></code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--sourcelttreegtcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--sourcelttreegtcode"></a><code>--source=<tree></code> </dt> <dd> <p>Restore the working tree files with the content from the given tree. It is common to specify the source tree by naming a commit, branch or tag associated with it.</p> <div class="paragraph"> <p>If not specified, the contents are restored from <code>HEAD</code> if <code>--staged</code> is given, otherwise from the index.</p> </div> <div class="paragraph"> <p>As a special case, you may use <code>"<rev-A>...<rev-B>"</code> as a shortcut for the merge base of <em><rev-A></em> and <em><rev-B></em> if there is exactly one merge base. You can leave out at most one of <em><rev-A>_</em> and <em><rev-B></em>, in which case it defaults to <code>HEAD</code>.</p> </div> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code-pcode"> <a class="anchor" href="#Documentation/git-restore.txt-code-pcode"></a><code>-p</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--patchcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--patchcode"></a><code>--patch</code> </dt> <dd> <p>Interactively select hunks in the difference between the restore source and the restore location. See the "Interactive Mode" section of <a href='/docs/git-add'>git-add[1]</a> to learn how to operate the <code>--patch</code> mode.</p> <div class="paragraph"> <p>Note that <code>--patch</code> can accept no pathspec and will prompt to restore all modified paths.</p> </div> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code-Wcode"> <a class="anchor" href="#Documentation/git-restore.txt-code-Wcode"></a><code>-W</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--worktreecode"> <a class="anchor" href="#Documentation/git-restore.txt-code--worktreecode"></a><code>--worktree</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code-Scode"> <a class="anchor" href="#Documentation/git-restore.txt-code-Scode"></a><code>-S</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--stagedcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--stagedcode"></a><code>--staged</code> </dt> <dd> <p>Specify the restore location. If neither option is specified, by default the working tree is restored. Specifying <code>--staged</code> will only restore the index. Specifying both restores both.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code-qcode"> <a class="anchor" href="#Documentation/git-restore.txt-code-qcode"></a><code>-q</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--quietcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--quietcode"></a><code>--quiet</code> </dt> <dd> <p>Quiet, suppress feedback messages. Implies <code>--no-progress</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--progresscode"> <a class="anchor" href="#Documentation/git-restore.txt-code--progresscode"></a><code>--progress</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--no-progresscode"> <a class="anchor" href="#Documentation/git-restore.txt-code--no-progresscode"></a><code>--no-progress</code> </dt> <dd> <p>Progress status is reported on the standard error stream by default when it is attached to a terminal, unless <code>--quiet</code> is specified. This flag enables progress reporting even if not attached to a terminal, regardless of <code>--quiet</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--ourscode"> <a class="anchor" href="#Documentation/git-restore.txt-code--ourscode"></a><code>--ours</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--theirscode"> <a class="anchor" href="#Documentation/git-restore.txt-code--theirscode"></a><code>--theirs</code> </dt> <dd> <p>When restoring files in the working tree from the index, use stage #2 (<code>ours</code>) or #3 (<code>theirs</code>) for unmerged paths. This option cannot be used when checking out paths from a tree-ish (i.e. with the <code>--source</code> option).</p> <div class="paragraph"> <p>Note that during <code>git rebase</code> and <code>git pull --rebase</code>, <code>ours</code> and <code>theirs</code> may appear swapped. See the explanation of the same options in <a href='/docs/git-checkout'>git-checkout[1]</a> for details.</p> </div> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code-mcode"> <a class="anchor" href="#Documentation/git-restore.txt-code-mcode"></a><code>-m</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--mergecode"> <a class="anchor" href="#Documentation/git-restore.txt-code--mergecode"></a><code>--merge</code> </dt> <dd> <p>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 <code>--source</code> option).</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--conflictltstylegtcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--conflictltstylegtcode"></a><code>--conflict=<style></code> </dt> <dd> <p>The same as <code>--merge</code> option above, but changes the way the conflicting hunks are presented, overriding the <code>merge.conflictStyle</code> configuration variable. Possible values are <code>merge</code> (default), <code>diff3</code>, and <code>zdiff3</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--ignore-unmergedcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--ignore-unmergedcode"></a><code>--ignore-unmerged</code> </dt> <dd> <p>When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither <code>--ours</code>, <code>--theirs</code>, <code>--merge</code> or <code>--conflict</code> is specified. Unmerged paths on the working tree are left alone.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--ignore-skip-worktree-bitscode"> <a class="anchor" href="#Documentation/git-restore.txt-code--ignore-skip-worktree-bitscode"></a><code>--ignore-skip-worktree-bits</code> </dt> <dd> <p>In sparse checkout mode, the default is to only update entries matched by <em><pathspec></em> and sparse patterns in <code>$GIT_DIR/info/sparse-checkout</code>. This option ignores the sparse patterns and unconditionally restores any files in <em><pathspec></em>.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--recurse-submodulescode"> <a class="anchor" href="#Documentation/git-restore.txt-code--recurse-submodulescode"></a><code>--recurse-submodules</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--no-recurse-submodulescode"> <a class="anchor" href="#Documentation/git-restore.txt-code--no-recurse-submodulescode"></a><code>--no-recurse-submodules</code> </dt> <dd> <p>If <em><pathspec></em> 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 <code>--no-recurse-submodules</code>) is used, submodules working trees will not be updated. Just like <a href='/docs/git-checkout'>git-checkout[1]</a>, this will detach <code>HEAD</code> of the submodule.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--overlaycode"> <a class="anchor" href="#Documentation/git-restore.txt-code--overlaycode"></a><code>--overlay</code> </dt> <dt class="hdlist1" id="Documentation/git-restore.txt-code--no-overlaycode"> <a class="anchor" href="#Documentation/git-restore.txt-code--no-overlaycode"></a><code>--no-overlay</code> </dt> <dd> <p>In overlay mode, never remove files when restoring. In no-overlay mode, remove tracked files that do not appear in the <em><tree></em> of <code>--source=<tree></code>, to make them match <em><tree></em> exactly. The default is no-overlay mode.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--pathspec-from-fileltfilegtcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--pathspec-from-fileltfilegtcode"></a><code>--pathspec-from-file=<file></code> </dt> <dd> <p>Pathspec is passed in <em><file></em> instead of commandline args. If <em><file></em> is exactly <code>-</code> then standard input is used. Pathspec elements are separated by <em>LF</em> or <em>CR</em>/<em>LF</em>. Pathspec elements can be quoted as explained for the configuration variable <code>core.quotePath</code> (see <a href='/docs/git-config'>git-config[1]</a>). See also <code>--pathspec-file-nul</code> and global <code>--literal-pathspecs</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--pathspec-file-nulcode"> <a class="anchor" href="#Documentation/git-restore.txt-code--pathspec-file-nulcode"></a><code>--pathspec-file-nul</code> </dt> <dd> <p>Only meaningful with <code>--pathspec-from-file</code>. Pathspec elements are separated with <em>NUL</em> character and all other characters are taken literally (including newlines and quotes).</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-code--code"> <a class="anchor" href="#Documentation/git-restore.txt-code--code"></a><code>--</code> </dt> <dd> <p>Do not interpret any more arguments as options.</p> </dd> <dt class="hdlist1" id="Documentation/git-restore.txt-codeltpathspecgtcode"> <a class="anchor" href="#Documentation/git-restore.txt-codeltpathspecgtcode"></a><code><pathspec>...</code> </dt> <dd> <p>Limits the paths affected by the operation.</p> <div class="paragraph"> <p>For more details, see the <em>pathspec</em> entry in <a href='/docs/gitglossary'>gitglossary[7]</a>.</p> </div> </dd> </dl> </div> </div> </div> <div class="sect1"> <h2 id="_examples"><a class="anchor" href="#_examples"></a>EXAMPLES</h2> <div class="sectionbody"> <div class="paragraph"> <p>The following sequence switches to the <code>master</code> branch, reverts the <code>Makefile</code> to two revisions back, deletes <code>hello.c</code> by mistake, and gets it back from the index.</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git switch master $ git restore --source master~2 Makefile <b class="conum">(1)</b> $ rm -f hello.c $ git restore hello.c <b class="conum">(2)</b></pre> </div> </div> <div class="colist arabic"> <ol> <li> <p>take a file out of another commit</p> </li> <li> <p>restore <code>hello.c</code> from the index</p> </li> </ol> </div> <div class="paragraph"> <p>If you want to restore <em>all</em> C source files to match the version in the index, you can say</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git restore '*.c'</pre> </div> </div> <div class="paragraph"> <p>Note the quotes around <code>*.c</code>. The file <code>hello.c</code> 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).</p> </div> <div class="paragraph"> <p>To restore all files in the current directory</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git restore .</pre> </div> </div> <div class="paragraph"> <p>or to restore all working tree files with <em>top</em> pathspec magic (see <a href='/docs/gitglossary'>gitglossary[7]</a>)</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git restore :/</pre> </div> </div> <div class="paragraph"> <p>To restore a file in the index to match the version in <code>HEAD</code> (this is the same as using <a href='/docs/git-reset'>git-reset[1]</a>)</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git restore --staged hello.c</pre> </div> </div> <div class="paragraph"> <p>or you can restore both the index and the working tree (this is the same as using <a href='/docs/git-checkout'>git-checkout[1]</a>)</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git restore --source=HEAD --staged --worktree hello.c</pre> </div> </div> <div class="paragraph"> <p>or the short form which is more practical but less readable:</p> </div> <div class="listingblock"> <div class="content"> <pre>$ git restore -s@ -SW hello.c</pre> </div> </div> </div> </div> <div class="sect1"> <h2 id="_see_also"><a class="anchor" href="#_see_also"></a>SEE ALSO</h2> <div class="sectionbody"> <div class="paragraph"> <p><a href='/docs/git-checkout'>git-checkout[1]</a>, <a href='/docs/git-reset'>git-reset[1]</a></p> </div> </div> </div> <div class="sect1"> <h2 id="_git"><a class="anchor" href="#_git"></a>GIT</h2> <div class="sectionbody"> <div class="paragraph"> <p>Part of the <a href='/docs/git'>git[1]</a> suite</p> </div> </div> </div> <h3 hidden="true" data-pagefind-weight="10">restore</h3> </div> </div> </div> <footer> <div class="site-source"> <a href="/site">About this site</a><br> Patches, suggestions, and comments are welcome. </div> <div class="sfc-member"> Git is a member of <a href="/sfc">Software Freedom Conservancy</a> </div> </footer> <a href="#top" class="no-js scrollToTop" id="scrollToTop" data-label="Scroll to top"> <img src="/images/icons/chevron-up@2x.png" width="20" height="20" alt="scroll-to-top"/> </a> <script src="/js/jquery-1.7.1.min.js"></script> <script src="/js/jquery-ui-1.8.18.custom.min.js"></script> <script src="/js/jquery.defaultvalue.js"></script> <script src="/js/session.min.js"></script> <script src="/js/modernizr.js"></script> <script src="/js/modernize.js"></script> <script src="/js/application.min.js"></script> </div> </body> </html>