1GIT-RESTORE(1) Git Manual GIT-RESTORE(1)
2
3
4
6 git-restore - Restore working tree files
7
9 git restore [<options>] [--source=<tree>] [--staged] [--worktree] <pathspec>...
10 git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [<pathspec>...]
11
12
14 Restore specified paths in the working tree with some contents from a
15 restore source. If a path is tracked but does not exist in the restore
16 source, it will be removed to match the source.
17
18 The command can also be used to restore the content in the index with
19 --staged, or restore both the working tree and the index with --staged
20 --worktree.
21
22 By default, the restore sources for working tree and the index are the
23 index and HEAD respectively. --source could be used to specify a commit
24 as the restore source.
25
26 See "Reset, restore and revert" in git(1) for the differences between
27 the three commands.
28
29 THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
30
32 -s <tree>, --source=<tree>
33 Restore the working tree files with the content from the given
34 tree. It is common to specify the source tree by naming a commit,
35 branch or tag associated with it.
36
37 If not specified, the default restore source for the working tree
38 is the index, and the default restore source for the index is HEAD.
39 When both --staged and --worktree are specified, --source must also
40 be specified.
41
42 -p, --patch
43 Interactively select hunks in the difference between the restore
44 source and the restore location. See the “Interactive Mode” section
45 of git-add(1) to learn how to operate the --patch mode.
46
47 Note that --patch can accept no pathspec and will prompt to restore
48 all modified paths.
49
50 -W, --worktree, -S, --staged
51 Specify the restore location. If neither option is specified, by
52 default the working tree is restored. Specifying --staged will only
53 restore the index. Specifying both restores both.
54
55 -q, --quiet
56 Quiet, suppress feedback messages. Implies --no-progress.
57
58 --progress, --no-progress
59 Progress status is reported on the standard error stream by default
60 when it is attached to a terminal, unless --quiet is specified.
61 This flag enables progress reporting even if not attached to a
62 terminal, regardless of --quiet.
63
64 --ours, --theirs
65 When restoring files in the working tree from the index, use stage
66 #2 (ours) or #3 (theirs) for unmerged paths.
67
68 Note that during git rebase and git pull --rebase, ours and theirs
69 may appear swapped. See the explanation of the same options in git-
70 checkout(1) for details.
71
72 -m, --merge
73 When restoring files on the working tree from the index, recreate
74 the conflicted merge in the unmerged paths.
75
76 --conflict=<style>
77 The same as --merge option above, but changes the way the
78 conflicting hunks are presented, overriding the merge.conflictStyle
79 configuration variable. Possible values are "merge" (default) and
80 "diff3" (in addition to what is shown by "merge" style, shows the
81 original contents).
82
83 --ignore-unmerged
84 When restoring files on the working tree from the index, do not
85 abort the operation if there are unmerged entries and neither
86 --ours, --theirs, --merge or --conflict is specified. Unmerged
87 paths on the working tree are left alone.
88
89 --ignore-skip-worktree-bits
90 In sparse checkout mode, by default is to only update entries
91 matched by <pathspec> and sparse patterns in
92 $GIT_DIR/info/sparse-checkout. This option ignores the sparse
93 patterns and unconditionally restores any files in <pathspec>.
94
95 --overlay, --no-overlay
96 In overlay mode, the command never removes files when restoring. In
97 no-overlay mode, tracked files that do not appear in the --source
98 tree are removed, to make them match <tree> exactly. The default is
99 no-overlay mode.
100
102 The following sequence switches to the master branch, reverts the
103 Makefile to two revisions back, deletes hello.c by mistake, and gets it
104 back from the index.
105
106 $ git switch master
107 $ git restore --source master~2 Makefile [1m(1)
108 $ rm -f hello.c
109 $ git restore hello.c [1m(2)
110
111
112 1. take a file out of another commit
113 2. restore hello.c from the index
114
115 If you want to restore all C source files to match the version in the
116 index, you can say
117
118 $ git restore '*.c'
119
120
121 Note the quotes around *.c. The file hello.c will also be restored,
122 even though it is no longer in the working tree, because the file
123 globbing is used to match entries in the index (not in the working tree
124 by the shell).
125
126 To restore all files in the current directory
127
128 $ git restore .
129
130
131 or to restore all working tree files with top pathspec magic (see
132 gitglossary(7))
133
134 $ git restore :/
135
136
137 To restore a file in the index to match the version in HEAD (this is
138 the same as using git-reset(1))
139
140 $ git restore --staged hello.c
141
142
143 or you can restore both the index and the working tree (this the same
144 as using git-checkout(1))
145
146 $ git restore --source=HEAD --staged --worktree hello.c
147
148
149 or the short form which is more practical but less readable:
150
151 $ git restore -s@ -SW hello.c
152
153
155 git-checkout(1), git-reset(1)
156
158 Part of the git(1) suite
159
160
161
162Git 2.24.1 12/10/2019 GIT-RESTORE(1)