Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 1 | git-restore(1) |
| 2 | ============== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-restore - Restore working tree files |
| 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| 10 | [verse] |
Alexandr Miloslavskiy | cfd9376 | 2019-12-03 14:02:17 +0000 | [diff] [blame] | 11 | 'git restore' [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>... |
Alexandr Miloslavskiy | a9aecc7 | 2019-12-03 14:02:18 +0000 | [diff] [blame] | 12 | 'git restore' [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul] |
Alexandr Miloslavskiy | cfd9376 | 2019-12-03 14:02:17 +0000 | [diff] [blame] | 13 | 'git restore' (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...] |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 14 | |
| 15 | DESCRIPTION |
| 16 | ----------- |
| 17 | Restore specified paths in the working tree with some contents from a |
| 18 | restore source. If a path is tracked but does not exist in the restore |
| 19 | source, it will be removed to match the source. |
| 20 | |
| 21 | The command can also be used to restore the content in the index with |
| 22 | `--staged`, or restore both the working tree and the index with |
| 23 | `--staged --worktree`. |
| 24 | |
Eric Sunshine | 088018e | 2020-05-05 03:17:16 -0400 | [diff] [blame] | 25 | By default, if `--staged` is given, the contents are restored from `HEAD`, |
| 26 | otherwise from the index. Use `--source` to restore from a different commit. |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 27 | |
| 28 | See "Reset, restore and revert" in linkgit:git[1] for the differences |
| 29 | between the three commands. |
| 30 | |
Nguyễn Thái Ngọc Duy | 4e43b7f | 2019-04-25 16:46:00 +0700 | [diff] [blame] | 31 | THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. |
| 32 | |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 33 | OPTIONS |
| 34 | ------- |
| 35 | -s <tree>:: |
| 36 | --source=<tree>:: |
| 37 | Restore the working tree files with the content from the given |
| 38 | tree. It is common to specify the source tree by naming a |
| 39 | commit, branch or tag associated with it. |
| 40 | + |
Eric Sunshine | 088018e | 2020-05-05 03:17:16 -0400 | [diff] [blame] | 41 | If not specified, the contents are restored from `HEAD` if `--staged` is |
| 42 | given, otherwise from the index. |
Denton Liu | c693ef7 | 2020-10-07 00:56:16 -0700 | [diff] [blame] | 43 | + |
| 44 | As a special case, you may use `"A...B"` as a shortcut for the |
| 45 | merge base of `A` and `B` if there is exactly one merge base. You can |
| 46 | leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 47 | |
| 48 | -p:: |
| 49 | --patch:: |
| 50 | Interactively select hunks in the difference between the |
| 51 | restore source and the restore location. See the ``Interactive |
| 52 | Mode'' section of linkgit:git-add[1] to learn how to operate |
| 53 | the `--patch` mode. |
| 54 | + |
| 55 | Note that `--patch` can accept no pathspec and will prompt to restore |
| 56 | all modified paths. |
| 57 | |
| 58 | -W:: |
| 59 | --worktree:: |
| 60 | -S:: |
| 61 | --staged:: |
| 62 | Specify the restore location. If neither option is specified, |
| 63 | by default the working tree is restored. Specifying `--staged` |
| 64 | will only restore the index. Specifying both restores both. |
| 65 | |
| 66 | -q:: |
| 67 | --quiet:: |
| 68 | Quiet, suppress feedback messages. Implies `--no-progress`. |
| 69 | |
| 70 | --progress:: |
| 71 | --no-progress:: |
| 72 | Progress status is reported on the standard error stream |
| 73 | by default when it is attached to a terminal, unless `--quiet` |
| 74 | is specified. This flag enables progress reporting even if not |
| 75 | attached to a terminal, regardless of `--quiet`. |
| 76 | |
| 77 | --ours:: |
| 78 | --theirs:: |
| 79 | When restoring files in the working tree from the index, use |
| 80 | stage #2 ('ours') or #3 ('theirs') for unmerged paths. |
| 81 | + |
| 82 | Note that during `git rebase` and `git pull --rebase`, 'ours' and |
| 83 | 'theirs' may appear swapped. See the explanation of the same options |
| 84 | in linkgit:git-checkout[1] for details. |
| 85 | |
| 86 | -m:: |
| 87 | --merge:: |
| 88 | When restoring files on the working tree from the index, |
| 89 | recreate the conflicted merge in the unmerged paths. |
| 90 | |
| 91 | --conflict=<style>:: |
| 92 | The same as `--merge` option above, but changes the way the |
| 93 | conflicting hunks are presented, overriding the |
| 94 | `merge.conflictStyle` configuration variable. Possible values |
Elijah Newren | ddfc44a8 | 2021-12-01 00:05:07 +0000 | [diff] [blame] | 95 | are "merge" (default), "diff3", and "zdiff3". |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 96 | |
| 97 | --ignore-unmerged:: |
| 98 | When restoring files on the working tree from the index, do |
| 99 | not abort the operation if there are unmerged entries and |
| 100 | neither `--ours`, `--theirs`, `--merge` or `--conflict` is |
| 101 | specified. Unmerged paths on the working tree are left alone. |
| 102 | |
| 103 | --ignore-skip-worktree-bits:: |
| 104 | In sparse checkout mode, by default is to only update entries |
| 105 | matched by `<pathspec>` and sparse patterns in |
| 106 | $GIT_DIR/info/sparse-checkout. This option ignores the sparse |
| 107 | patterns and unconditionally restores any files in |
| 108 | `<pathspec>`. |
| 109 | |
Damien Robert | b3cec57 | 2020-04-06 15:57:06 +0200 | [diff] [blame] | 110 | --recurse-submodules:: |
| 111 | --no-recurse-submodules:: |
| 112 | If `<pathspec>` names an active submodule and the restore location |
| 113 | includes the working tree, the submodule will only be updated if |
| 114 | this option is given, in which case its working tree will be |
| 115 | restored to the commit recorded in the superproject, and any local |
| 116 | modifications overwritten. If nothing (or |
| 117 | `--no-recurse-submodules`) is used, submodules working trees will |
| 118 | not be updated. Just like linkgit:git-checkout[1], this will detach |
| 119 | `HEAD` of the submodule. |
| 120 | |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 121 | --overlay:: |
| 122 | --no-overlay:: |
| 123 | In overlay mode, the command never removes files when |
| 124 | restoring. In no-overlay mode, tracked files that do not |
| 125 | appear in the `--source` tree are removed, to make them match |
| 126 | `<tree>` exactly. The default is no-overlay mode. |
| 127 | |
Alexandr Miloslavskiy | a9aecc7 | 2019-12-03 14:02:18 +0000 | [diff] [blame] | 128 | --pathspec-from-file=<file>:: |
| 129 | Pathspec is passed in `<file>` instead of commandline args. If |
| 130 | `<file>` is exactly `-` then standard input is used. Pathspec |
| 131 | elements are separated by LF or CR/LF. Pathspec elements can be |
| 132 | quoted as explained for the configuration variable `core.quotePath` |
| 133 | (see linkgit:git-config[1]). See also `--pathspec-file-nul` and |
| 134 | global `--literal-pathspecs`. |
| 135 | |
| 136 | --pathspec-file-nul:: |
| 137 | Only meaningful with `--pathspec-from-file`. Pathspec elements are |
| 138 | separated with NUL character and all other characters are taken |
| 139 | literally (including newlines and quotes). |
| 140 | |
Alexandr Miloslavskiy | cfd9376 | 2019-12-03 14:02:17 +0000 | [diff] [blame] | 141 | \--:: |
| 142 | Do not interpret any more arguments as options. |
| 143 | |
| 144 | <pathspec>...:: |
| 145 | Limits the paths affected by the operation. |
| 146 | + |
| 147 | For more details, see the 'pathspec' entry in linkgit:gitglossary[7]. |
| 148 | |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 149 | EXAMPLES |
| 150 | -------- |
| 151 | |
| 152 | The following sequence switches to the `master` branch, reverts the |
| 153 | `Makefile` to two revisions back, deletes hello.c by mistake, and gets |
| 154 | it back from the index. |
| 155 | |
| 156 | ------------ |
| 157 | $ git switch master |
| 158 | $ git restore --source master~2 Makefile <1> |
| 159 | $ rm -f hello.c |
| 160 | $ git restore hello.c <2> |
| 161 | ------------ |
| 162 | |
| 163 | <1> take a file out of another commit |
| 164 | <2> restore hello.c from the index |
| 165 | |
| 166 | If you want to restore _all_ C source files to match the version in |
| 167 | the index, you can say |
| 168 | |
| 169 | ------------ |
| 170 | $ git restore '*.c' |
| 171 | ------------ |
| 172 | |
| 173 | Note the quotes around `*.c`. The file `hello.c` will also be |
| 174 | restored, even though it is no longer in the working tree, because the |
| 175 | file globbing is used to match entries in the index (not in the |
| 176 | working tree by the shell). |
| 177 | |
| 178 | To restore all files in the current directory |
| 179 | |
| 180 | ------------ |
| 181 | $ git restore . |
| 182 | ------------ |
| 183 | |
| 184 | or to restore all working tree files with 'top' pathspec magic (see |
| 185 | linkgit:gitglossary[7]) |
| 186 | |
| 187 | ------------ |
| 188 | $ git restore :/ |
| 189 | ------------ |
| 190 | |
| 191 | To restore a file in the index to match the version in `HEAD` (this is |
| 192 | the same as using linkgit:git-reset[1]) |
| 193 | |
| 194 | ------------ |
| 195 | $ git restore --staged hello.c |
| 196 | ------------ |
| 197 | |
| 198 | or you can restore both the index and the working tree (this the same |
| 199 | as using linkgit:git-checkout[1]) |
| 200 | |
| 201 | ------------ |
| 202 | $ git restore --source=HEAD --staged --worktree hello.c |
| 203 | ------------ |
| 204 | |
| 205 | or the short form which is more practical but less readable: |
| 206 | |
| 207 | ------------ |
| 208 | $ git restore -s@ -SW hello.c |
| 209 | ------------ |
| 210 | |
| 211 | SEE ALSO |
| 212 | -------- |
| 213 | linkgit:git-checkout[1], |
| 214 | linkgit:git-reset[1] |
| 215 | |
| 216 | GIT |
| 217 | --- |
| 218 | Part of the linkgit:git[1] suite |