]>
Commit | Line | Data |
---|---|---|
215a7ad1 JH |
1 | git-reset(1) |
2 | ============ | |
7fc9d69f JH |
3 | |
4 | NAME | |
5 | ---- | |
215a7ad1 | 6 | git-reset - Reset current HEAD to the specified state. |
7fc9d69f JH |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
215a7ad1 | 10 | 'git-reset' [--mixed | --soft | --hard] [<commit-ish>] |
7fc9d69f JH |
11 | |
12 | DESCRIPTION | |
13 | ----------- | |
f67545ea LAS |
14 | Sets the current head to the specified commit and optionally resets the |
15 | index and working tree to match. | |
7fc9d69f | 16 | |
936a2342 AE |
17 | This command is useful if you notice some small error in a recent |
18 | commit (or set of commits) and want to redo that part without showing | |
19 | the undo in the history. | |
20 | ||
21 | If you want to undo a commit other than the latest on a branch, | |
22 | gitlink:git-revert[1] is your friend. | |
23 | ||
7fc9d69f JH |
24 | OPTIONS |
25 | ------- | |
f67545ea | 26 | --mixed:: |
936a2342 AE |
27 | Resets the index but not the working tree (ie, the changed files |
28 | are preserved but not marked for commit) and reports what has not | |
29 | been updated. This is the default action. | |
f67545ea LAS |
30 | |
31 | --soft:: | |
32 | Does not touch the index file nor the working tree at all, but | |
936a2342 AE |
33 | requires them to be in a good order. This leaves all your changed |
34 | files "Updated but not checked in", as gitlink:git-status[1] would | |
35 | put it. | |
7fc9d69f | 36 | |
f67545ea LAS |
37 | --hard:: |
38 | Matches the working tree and index to that of the tree being | |
936a2342 AE |
39 | switched to. Any changes to tracked files in the working tree |
40 | since <commit-ish> are lost. | |
7fc9d69f | 41 | |
f67545ea LAS |
42 | <commit-ish>:: |
43 | Commit to make the current HEAD. | |
7fc9d69f | 44 | |
1e2ccd3a JH |
45 | Examples |
46 | ~~~~~~~~ | |
47 | ||
48 | Undo a commit and redo:: | |
49 | + | |
50 | ------------ | |
51 | $ git commit ... | |
52 | $ git reset --soft HEAD^ <1> | |
53 | $ edit <2> | |
54 | $ git commit -a -c ORIG_HEAD <3> | |
55 | ||
56 | <1> This is most often done when you remembered what you | |
57 | just committed is incomplete, or you misspelled your commit | |
58 | message, or both. Leaves working tree as it was before "reset". | |
59 | <2> make corrections to working tree files. | |
60 | <3> "reset" copies the old head to .git/ORIG_HEAD; redo the | |
61 | commit by starting with its log message. If you do not need to | |
62 | edit the message further, you can give -C option instead. | |
63 | ------------ | |
64 | ||
65 | Undo commits permanently:: | |
66 | + | |
67 | ------------ | |
68 | $ git commit ... | |
69 | $ git reset --hard HEAD~3 <1> | |
70 | ||
71 | <1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad | |
72 | and you do not want to ever see them again. Do *not* do this if | |
73 | you have already given these commits to somebody else. | |
74 | ------------ | |
75 | ||
76 | Undo a commit, making it a topic branch:: | |
77 | + | |
78 | ------------ | |
79 | $ git branch topic/wip <1> | |
80 | $ git reset --hard HEAD~3 <2> | |
81 | $ git checkout topic/wip <3> | |
82 | ||
83 | <1> You have made some commits, but realize they were premature | |
84 | to be in the "master" branch. You want to continue polishing | |
85 | them in a topic branch, so create "topic/wip" branch off of the | |
86 | current HEAD. | |
87 | <2> Rewind the master branch to get rid of those three commits. | |
88 | <3> Switch to "topic/wip" branch and keep working. | |
89 | ------------ | |
90 | ||
91 | Undo update-index:: | |
92 | + | |
93 | ------------ | |
94 | $ edit <1> | |
95 | $ git-update-index frotz.c filfre.c | |
96 | $ mailx <2> | |
97 | $ git reset <3> | |
98 | $ git pull git://info.example.com/ nitfol <4> | |
99 | ||
100 | <1> you are happily working on something, and find the changes | |
101 | in these files are in good order. You do not want to see them | |
102 | when you run "git diff", because you plan to work on other files | |
103 | and changes with these files are distracting. | |
104 | <2> somebody asks you to pull, and the changes sounds worthy of merging. | |
105 | <3> however, you already dirtied the index (i.e. your index does | |
106 | not match the HEAD commit). But you know the pull you are going | |
107 | to make does not affect frotz.c nor filfre.c, so you revert the | |
108 | index changes for these two files. Your changes in working tree | |
109 | remain there. | |
110 | <4> then you can pull and merge, leaving frotz.c and filfre.c | |
111 | changes still in the working tree. | |
112 | ------------ | |
113 | ||
114 | ||
7fc9d69f JH |
115 | Author |
116 | ------ | |
117 | Written by Junio C Hamano <junkio@cox.net> and Linus Torvalds <torvalds@osdl.org> | |
118 | ||
119 | Documentation | |
120 | -------------- | |
121 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. | |
122 | ||
123 | GIT | |
124 | --- | |
a7154e91 | 125 | Part of the gitlink:git[7] suite |
7fc9d69f | 126 |