bfa0082fd8817726a22f7cfffdd61cd70ed80797
[git.git] / man1 / git-reset.1
1 .\"Generated by db2man.xsl. Don't modify this, modify the source.
2 .de Sh \" Subsection
3 .br
4 .if t .Sp
5 .ne 5
6 .PP
7 \fB\\$1\fR
8 .PP
9 ..
10 .de Sp \" Vertical space (when we can't use .PP)
11 .if t .sp .5v
12 .if n .sp
13 ..
14 .de Ip \" List item
15 .br
16 .ie \\n(.$>=3 .ne \\$3
17 .el .ne 3
18 .IP "\\$1" \\$2
19 ..
20 .TH "GIT-RESET" 1 "" "" ""
21 .SH NAME
22 git-reset \- Reset current HEAD to the specified state
23 .SH "SYNOPSIS"
24
25
26 \fIgit\-reset\fR [\-\-mixed | \-\-soft | \-\-hard] [<commit\-ish>]
27
28 .SH "DESCRIPTION"
29
30
31 Sets the current head to the specified commit and optionally resets the index and working tree to match\&.
32
33
34 This command is useful if you notice some small error in a recent commit (or set of commits) and want to redo that part without showing the undo in the history\&.
35
36
37 If you want to undo a commit other than the latest on a branch, \fBgit\-revert\fR(1) is your friend\&.
38
39 .SH "OPTIONS"
40
41 .TP
42 \-\-mixed
43 Resets the index but not the working tree (ie, the changed files are preserved but not marked for commit) and reports what has not been updated\&. This is the default action\&.
44
45 .TP
46 \-\-soft
47 Does not touch the index file nor the working tree at all, but requires them to be in a good order\&. This leaves all your changed files "Updated but not checked in", as \fBgit\-status\fR(1) would put it\&.
48
49 .TP
50 \-\-hard
51 Matches the working tree and index to that of the tree being switched to\&. Any changes to tracked files in the working tree since <commit\-ish> are lost\&.
52
53 .TP
54 <commit\-ish>
55 Commit to make the current HEAD\&.
56
57 .SS "Examples"
58
59 .TP
60 Undo a commit and redo
61
62 .nf
63 $ git commit \&.\&.\&.
64 $ git reset \-\-soft HEAD^      \fB(1)\fR
65 $ edit                        \fB(2)\fR
66 $ git commit \-a \-c ORIG_HEAD  \fB(3)\fR
67 .fi
68 .sp
69 \fB1. \fRThis is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both\&. Leaves working tree as it was before "reset"\&.
70 .br
71 \fB2. \fRmake corrections to working tree files\&.
72 .br
73 \fB3. \fR"reset" copies the old head to \&.git/ORIG_HEAD; redo the commit by starting with its log message\&. If you do not need to edit the message further, you can give \-C option instead\&.
74 .br
75
76
77 .TP
78 Undo commits permanently
79
80 .nf
81 $ git commit \&.\&.\&.
82 $ git reset \-\-hard HEAD~3   \fB(1)\fR
83 .fi
84 .sp
85 \fB1. \fRThe last three commits (HEAD, HEAD^, and HEAD~2) were bad and you do not want to ever see them again\&. Do \fInot\fR do this if you have already given these commits to somebody else\&.
86 .br
87
88
89 .TP
90 Undo a commit, making it a topic branch
91
92 .nf
93 $ git branch topic/wip     \fB(1)\fR
94 $ git reset \-\-hard HEAD~3  \fB(2)\fR
95 $ git checkout topic/wip   \fB(3)\fR
96 .fi
97 .sp
98 \fB1. \fRYou have made some commits, but realize they were premature to be in the "master" branch\&. You want to continue polishing them in a topic branch, so create "topic/wip" branch off of the current HEAD\&.
99 .br
100 \fB2. \fRRewind the master branch to get rid of those three commits\&.
101 .br
102 \fB3. \fRSwitch to "topic/wip" branch and keep working\&.
103 .br
104
105
106 .TP
107 Undo update\-index
108
109 .nf
110 $ edit                                     \fB(1)\fR
111 $ git\-update\-index frotz\&.c filfre\&.c
112 $ mailx                                    \fB(2)\fR
113 $ git reset                                \fB(3)\fR
114 $ git pull git://info\&.example\&.com/ nitfol  \fB(4)\fR
115 .fi
116 .sp
117 \fB1. \fRyou are happily working on something, and find the changes in these files are in good order\&. You do not want to see them when you run "git diff", because you plan to work on other files and changes with these files are distracting\&.
118 .br
119 \fB2. \fRsomebody asks you to pull, and the changes sounds worthy of merging\&.
120 .br
121 \fB3. \fRhowever, you already dirtied the index (i\&.e\&. your index does not match the HEAD commit)\&. But you know the pull you are going to make does not affect frotz\&.c nor filfre\&.c, so you revert the index changes for these two files\&. Your changes in working tree remain there\&.
122 .br
123 \fB4. \fRthen you can pull and merge, leaving frotz\&.c and filfre\&.c changes still in the working tree\&.
124 .br
125
126
127 .TP
128 Undo a merge or pull
129
130 .nf
131 $ git pull                         \fB(1)\fR
132 Trying really trivial in\-index merge\&.\&.\&.
133 fatal: Merge requires file\-level merging
134 Nope\&.
135 \&.\&.\&.
136 Auto\-merging nitfol
137 CONFLICT (content): Merge conflict in nitfol
138 Automatic merge failed/prevented; fix up by hand
139 $ git reset \-\-hard                 \fB(2)\fR
140 $ git pull \&. topic/branch          \fB(3)\fR
141 Updating from 41223\&.\&.\&. to 13134\&.\&.\&.
142 Fast forward
143 $ git reset \-\-hard ORIG_HEAD       \fB(4)\fR
144 .fi
145 .sp
146 \fB1. \fRtry to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later\&.
147 .br
148 \fB2. \fR"pull" has not made merge commit, so "git reset \-\-hard" which is a synonym for "git reset \-\-hard HEAD" clears the mess from the index file and the working tree\&.
149 .br
150 \fB3. \fRmerge a topic branch into the current branch, which resulted in a fast forward\&.
151 .br
152 \fB4. \fRbut you decided that the topic branch is not ready for public consumption yet\&. "pull" or "merge" always leaves the original tip of the current branch in ORIG_HEAD, so resetting hard to it brings your index file and the working tree back to that state, and resets the tip of the branch to that commit\&.
153 .br
154
155
156 .TP
157 Interrupted workflow
158 Suppose you are interrupted by an urgent fix request while you are in the middle of a large change\&. The files in your working tree are not in any shape to be committed yet, but you need to get to the other branch for a quick bugfix\&.
159
160 .nf
161 $ git checkout feature ;# you were working in "feature" branch and
162 $ work work work       ;# got interrupted
163 $ git commit \-a \-m 'snapshot WIP'                 \fB(1)\fR
164 $ git checkout master
165 $ fix fix fix
166 $ git commit ;# commit with real log
167 $ git checkout feature
168 $ git reset \-\-soft HEAD^ ;# go back to WIP state  \fB(2)\fR
169 $ git reset                                       \fB(3)\fR
170 .fi
171 .sp
172 \fB1. \fRThis commit will get blown away so a throw\-away log message is OK\&.
173 .br
174 \fB2. \fRThis removes the \fIWIP\fR commit from the commit history, and sets your working tree to the state just before you made that snapshot\&.
175 .br
176 \fB3. \fRAt this point the index file still has all the WIP changes you committed as \fIsnapshot WIP\fR\&. This updates the index to show your WIP files as uncommitted\&.
177 .br
178
179
180 .SH "AUTHOR"
181
182
183 Written by Junio C Hamano <junkio@cox\&.net> and Linus Torvalds <torvalds@osdl\&.org>
184
185 .SH "DOCUMENTATION"
186
187
188 Documentation by Junio C Hamano and the git\-list <git@vger\&.kernel\&.org>\&.
189
190 .SH "GIT"
191
192
193 Part of the \fBgit\fR(7) suite
194