@@ -15,17 +15,24 @@ SYNOPSIS
15
15
DESCRIPTION
16
16
-----------
17
17
In the first and second form, copy entries from <commit> to the index.
18
- In the third form, set the current branch to <commit>, optionally
19
- modifying index and worktree to match. The <commit> defaults to HEAD
18
+ In the third form, set the current branch head (HEAD) to <commit>, optionally
19
+ modifying index and working tree to match. The <commit> defaults to HEAD
20
20
in all forms.
21
21
22
22
'git reset' [-q] [<commit>] [--] <paths>...::
23
23
This form resets the index entries for all <paths> to their
24
- state at the <commit>. (It does not affect the worktree , nor
24
+ state at <commit>. (It does not affect the working tree , nor
25
25
the current branch.)
26
26
+
27
27
This means that `git reset <paths>` is the opposite of `git add
28
28
<paths>`.
29
+ +
30
+ After running `git reset <paths>` to update the index entry, you can
31
+ use linkgit:git-checkout[1] to check the contents out of the index to
32
+ the working tree.
33
+ Alternatively, using linkgit:git-checkout[1] and specifying a commit, you
34
+ can copy the contents of a path out of a commit to the index and to the
35
+ working tree in one go.
29
36
30
37
'git reset' --patch|-p [<commit>] [--] [<paths>...]::
31
38
Interactively select hunks in the difference between the index
@@ -36,39 +43,48 @@ This means that `git reset -p` is the opposite of `git add -p` (see
36
43
linkgit:git-add[1]).
37
44
38
45
'git reset' [--<mode>] [<commit>]::
39
- This form points the current branch to <commit> and then
40
- updates index and working tree according to <mode>, which must
41
- be one of the following:
46
+ This form resets the current branch head to <commit> and
47
+ possibly updates the index (resetting it to the tree of <commit>) and
48
+ the working tree depending on <mode>, which
49
+ must be one of the following:
42
50
+
43
51
--
44
52
--soft::
45
- Does not touch the index file nor the working tree at all, but
46
- requires them to be in a good order . This leaves all your changed
47
- files "Changes to be committed", as 'git status' would
48
- put it.
53
+ Does not touch the index file nor the working tree at all ( but
54
+ resets the head to <commit>, just like all modes do) . This leaves
55
+ all your changed files "Changes to be committed", as 'git status'
56
+ would put it.
49
57
50
58
--mixed::
51
59
Resets the index but not the working tree (i.e., the changed files
52
60
are preserved but not marked for commit) and reports what has not
53
61
been updated. This is the default action.
54
62
55
63
--hard::
56
- Matches the working tree and index to that of the tree being
57
- switched to. Any changes to tracked files in the working tree
58
- since <commit> are lost.
64
+ Resets the index and working tree. Any changes to tracked files in the
65
+ working tree since <commit> are discarded.
59
66
60
67
--merge::
61
- Resets the index to match the tree recorded by the named commit,
62
- and updates the files that are different between the named commit
63
- and the current commit in the working tree.
68
+ Resets the index and updates the files in the working tree that are
69
+ different between <commit> and HEAD, but keeps those which are
70
+ different between the index and working tree (i.e. which have changes
71
+ which have not been added).
72
+ If a file that is different between <commit> and the index has unstaged
73
+ changes, reset is aborted.
74
+ +
75
+ In other words, --merge does something like a 'git read-tree -u -m <commit>',
76
+ but carries forward unmerged index entries.
64
77
65
78
--keep::
66
- Reset the index to the given commit, keeping local changes in
67
- the working tree since the current commit, while updating
68
- working tree files without local changes to what appears in
69
- the given commit. If a file that is different between the
70
- current commit and the given commit has local changes, reset
71
- is aborted.
79
+ Resets the index, updates files in the working tree that are
80
+ different between <commit> and HEAD, but keeps those
81
+ which are different between HEAD and the working tree (i.e.
82
+ which have local changes).
83
+ If a file that is different between <commit> and HEAD has local changes,
84
+ reset is aborted.
85
+ +
86
+ In other words, --keep does a 2-way merge between <commit> and HEAD followed by
87
+ 'git reset --mixed <commit>'.
72
88
--
73
89
74
90
If you want to undo a commit other than the latest on a branch,
@@ -184,7 +200,7 @@ tip of the current branch in ORIG_HEAD, so resetting hard to it
184
200
brings your index file and the working tree back to that state,
185
201
and resets the tip of the branch to that commit.
186
202
187
- Undo a merge or pull inside a dirty work tree::
203
+ Undo a merge or pull inside a dirty working tree::
188
204
+
189
205
------------
190
206
$ git pull <1>
@@ -257,7 +273,7 @@ Suppose you are working on something and you commit it, and then you
257
273
continue working a bit more, but now you think that what you have in
258
274
your working tree should be in another branch that has nothing to do
259
275
with what you committed previously. You can start a new branch and
260
- reset it while keeping the changes in your work tree.
276
+ reset it while keeping the changes in your working tree.
261
277
+
262
278
------------
263
279
$ git tag start
@@ -294,8 +310,10 @@ In these tables, A, B, C and D are some different states of a
294
310
file. For example, the first line of the first table means that if a
295
311
file is in state A in the working tree, in state B in the index, in
296
312
state C in HEAD and in state D in the target, then "git reset --soft
297
- target" will put the file in state A in the working tree, in state B
298
- in the index and in state D in HEAD.
313
+ target" will leave the file in the working tree in state A and in the
314
+ index in state B. It resets (i.e. moves) the HEAD (i.e. the tip of
315
+ the current branch, if you are on one) to "target" (which has the file
316
+ in state D).
299
317
300
318
working index HEAD target working index HEAD
301
319
----------------------------------------------------
@@ -346,11 +364,11 @@ in the index and in state D in HEAD.
346
364
--keep B C C
347
365
348
366
"reset --merge" is meant to be used when resetting out of a conflicted
349
- merge. Any mergy operation guarantees that the work tree file that is
367
+ merge. Any mergy operation guarantees that the working tree file that is
350
368
involved in the merge does not have local change wrt the index before
351
- it starts, and that it writes the result out to the work tree. So if
369
+ it starts, and that it writes the result out to the working tree. So if
352
370
we see some difference between the index and the target and also
353
- between the index and the work tree, then it means that we are not
371
+ between the index and the working tree, then it means that we are not
354
372
resetting out from a state that a mergy operation left after failing
355
373
with a conflict. That is why we disallow --merge option in this case.
356
374
0 commit comments