d6860d43da2b3c778f0c43125fff698d0ae9f542
[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^ 
65 $ edit 
66 $ git commit \-a \-c ORIG_HEAD 
67
68  This is most often done when you remembered what you
69 just committed is incomplete, or you misspelled your commit
70 message, or both\&.  Leaves working tree as it was before "reset"\&.
71  make corrections to working tree files\&.
72  "reset" copies the old head to \&.git/ORIG_HEAD; redo the
73 commit by starting with its log message\&.  If you do not need to
74 edit the message further, you can give \-C option instead\&.
75 .fi
76
77 .TP
78 Undo commits permanently
79
80 .nf
81 $ git commit \&.\&.\&.
82 $ git reset \-\-hard HEAD~3 
83
84  The last three commits (HEAD, HEAD^, and HEAD~2) were bad
85 and you do not want to ever see them again\&.  Do *not* do this if
86 you have already given these commits to somebody else\&.
87 .fi
88
89 .TP
90 Undo a commit, making it a topic branch
91
92 .nf
93 $ git branch topic/wip 
94 $ git reset \-\-hard HEAD~3 
95 $ git checkout topic/wip 
96
97  You have made some commits, but realize they were premature
98 to be in the "master" branch\&.  You want to continue polishing
99 them in a topic branch, so create "topic/wip" branch off of the
100 current HEAD\&.
101  Rewind the master branch to get rid of those three commits\&.
102  Switch to "topic/wip" branch and keep working\&.
103 .fi
104
105 .TP
106 Undo update\-index
107
108 .nf
109 $ edit 
110 $ git\-update\-index frotz\&.c filfre\&.c
111 $ mailx 
112 $ git reset 
113 $ git pull git://info\&.example\&.com/ nitfol 
114
115  you are happily working on something, and find the changes
116 in these files are in good order\&.  You do not want to see them
117 when you run "git diff", because you plan to work on other files
118 and changes with these files are distracting\&.
119  somebody asks you to pull, and the changes sounds worthy of merging\&.
120  however, you already dirtied the index (i\&.e\&. your index does
121 not match the HEAD commit)\&.  But you know the pull you are going
122 to make does not affect frotz\&.c nor filfre\&.c, so you revert the
123 index changes for these two files\&.  Your changes in working tree
124 remain there\&.
125  then you can pull and merge, leaving frotz\&.c and filfre\&.c
126 changes still in the working tree\&.
127 .fi
128
129 .TP
130 Undo a merge or pull
131
132 .nf
133 $ git pull 
134 Trying really trivial in\-index merge\&.\&.\&.
135 fatal: Merge requires file\-level merging
136 Nope\&.
137 \&.\&.\&.
138 Auto\-merging nitfol
139 CONFLICT (content): Merge conflict in nitfol
140 Automatic merge failed/prevented; fix up by hand
141 $ git reset \-\-hard 
142
143  try to update from the upstream resulted in a lot of
144 conflicts; you were not ready to spend a lot of time merging
145 right now, so you decide to do that later\&.
146  "pull" has not made merge commit, so "git reset \-\-hard"
147 which is a synonym for "git reset \-\-hard HEAD" clears the mess
148 from the index file and the working tree\&.
149
150 $ git pull \&. topic/branch 
151 Updating from 41223\&.\&.\&. to 13134\&.\&.\&.
152 Fast forward
153 $ git reset \-\-hard ORIG_HEAD 
154
155  merge a topic branch into the current branch, which resulted
156 in a fast forward\&.
157  but you decided that the topic branch is not ready for public
158 consumption yet\&.  "pull" or "merge" always leaves the original
159 tip of the current branch in ORIG_HEAD, so resetting hard to it
160 brings your index file and the working tree back to that state,
161 and resets the tip of the branch to that commit\&.
162 .fi
163
164 .TP
165 Interrupted workflow
166 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\&.
167
168 .nf
169 $ git checkout feature ;# you were working in "feature" branch and
170 $ work work work       ;# got interrupted
171 $ git commit \-a \-m 'snapshot WIP' 
172 $ git checkout master
173 $ fix fix fix
174 $ git commit ;# commit with real log
175 $ git checkout feature
176 $ git reset \-\-soft HEAD^ ;# go back to WIP state 
177 $ git reset 
178
179  This commit will get blown away so a throw\-away log message is OK\&.
180  This removes the 'WIP' commit from the commit history, and sets
181     your working tree to the state just before you made that snapshot\&.
182  After , the index file still has all the WIP changes you
183     committed in \&.  This sets it to the last commit you were
184     basing the WIP changes on\&.
185 .fi
186
187 .SH "AUTHOR"
188
189
190 Written by Junio C Hamano <junkio@cox\&.net> and Linus Torvalds <torvalds@osdl\&.org>
191
192 .SH "DOCUMENTATION"
193
194
195 Documentation by Junio C Hamano and the git\-list <git@vger\&.kernel\&.org>\&.
196
197 .SH "GIT"
198
199
200 Part of the \fBgit\fR(7) suite
201