Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
| 2 | "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 6 | <meta name="generator" content="AsciiDoc 8.2.5" /> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | <style type="text/css"> |
| 8 | /* Debug borders */ |
| 9 | p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { |
| 10 | /* |
| 11 | border: 1px solid red; |
| 12 | */ |
| 13 | } |
| 14 | |
| 15 | body { |
| 16 | margin: 1em 5% 1em 5%; |
| 17 | } |
| 18 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 19 | a { |
| 20 | color: blue; |
| 21 | text-decoration: underline; |
| 22 | } |
| 23 | a:visited { |
| 24 | color: fuchsia; |
| 25 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 26 | |
| 27 | em { |
| 28 | font-style: italic; |
| 29 | } |
| 30 | |
| 31 | strong { |
| 32 | font-weight: bold; |
| 33 | } |
| 34 | |
| 35 | tt { |
| 36 | color: navy; |
| 37 | } |
| 38 | |
| 39 | h1, h2, h3, h4, h5, h6 { |
| 40 | color: #527bbd; |
| 41 | font-family: sans-serif; |
| 42 | margin-top: 1.2em; |
| 43 | margin-bottom: 0.5em; |
| 44 | line-height: 1.3; |
| 45 | } |
| 46 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 47 | h1, h2, h3 { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 48 | border-bottom: 2px solid silver; |
| 49 | } |
| 50 | h2 { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 51 | padding-top: 0.5em; |
| 52 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 53 | h3 { |
| 54 | float: left; |
| 55 | } |
| 56 | h3 + * { |
| 57 | clear: left; |
| 58 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 59 | |
| 60 | div.sectionbody { |
| 61 | font-family: serif; |
| 62 | margin-left: 0; |
| 63 | } |
| 64 | |
| 65 | hr { |
| 66 | border: 1px solid silver; |
| 67 | } |
| 68 | |
| 69 | p { |
| 70 | margin-top: 0.5em; |
| 71 | margin-bottom: 0.5em; |
| 72 | } |
| 73 | |
| 74 | pre { |
| 75 | padding: 0; |
| 76 | margin: 0; |
| 77 | } |
| 78 | |
| 79 | span#author { |
| 80 | color: #527bbd; |
| 81 | font-family: sans-serif; |
| 82 | font-weight: bold; |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 83 | font-size: 1.1em; |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | } |
| 85 | span#email { |
| 86 | } |
| 87 | span#revision { |
| 88 | font-family: sans-serif; |
| 89 | } |
| 90 | |
| 91 | div#footer { |
| 92 | font-family: sans-serif; |
| 93 | font-size: small; |
| 94 | border-top: 2px solid silver; |
| 95 | padding-top: 0.5em; |
| 96 | margin-top: 4.0em; |
| 97 | } |
| 98 | div#footer-text { |
| 99 | float: left; |
| 100 | padding-bottom: 0.5em; |
| 101 | } |
| 102 | div#footer-badges { |
| 103 | float: right; |
| 104 | padding-bottom: 0.5em; |
| 105 | } |
| 106 | |
| 107 | div#preamble, |
| 108 | div.tableblock, div.imageblock, div.exampleblock, div.verseblock, |
| 109 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 110 | div.admonitionblock { |
| 111 | margin-right: 10%; |
| 112 | margin-top: 1.5em; |
| 113 | margin-bottom: 1.5em; |
| 114 | } |
| 115 | div.admonitionblock { |
| 116 | margin-top: 2.5em; |
| 117 | margin-bottom: 2.5em; |
| 118 | } |
| 119 | |
| 120 | div.content { /* Block element content. */ |
| 121 | padding: 0; |
| 122 | } |
| 123 | |
| 124 | /* Block element titles. */ |
| 125 | div.title, caption.title { |
| 126 | font-family: sans-serif; |
| 127 | font-weight: bold; |
| 128 | text-align: left; |
| 129 | margin-top: 1.0em; |
| 130 | margin-bottom: 0.5em; |
| 131 | } |
| 132 | div.title + * { |
| 133 | margin-top: 0; |
| 134 | } |
| 135 | |
| 136 | td div.title:first-child { |
| 137 | margin-top: 0.0em; |
| 138 | } |
| 139 | div.content div.title:first-child { |
| 140 | margin-top: 0.0em; |
| 141 | } |
| 142 | div.content + div.title { |
| 143 | margin-top: 0.0em; |
| 144 | } |
| 145 | |
| 146 | div.sidebarblock > div.content { |
| 147 | background: #ffffee; |
| 148 | border: 1px solid silver; |
| 149 | padding: 0.5em; |
| 150 | } |
| 151 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 152 | div.listingblock { |
| 153 | margin-right: 0%; |
| 154 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 155 | div.listingblock > div.content { |
| 156 | border: 1px solid silver; |
| 157 | background: #f4f4f4; |
| 158 | padding: 0.5em; |
| 159 | } |
| 160 | |
| 161 | div.quoteblock > div.content { |
| 162 | padding-left: 2.0em; |
| 163 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 164 | |
| 165 | div.attribution { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 166 | text-align: right; |
| 167 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 168 | div.verseblock + div.attribution { |
| 169 | text-align: left; |
| 170 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 171 | |
| 172 | div.admonitionblock .icon { |
| 173 | vertical-align: top; |
| 174 | font-size: 1.1em; |
| 175 | font-weight: bold; |
| 176 | text-decoration: underline; |
| 177 | color: #527bbd; |
| 178 | padding-right: 0.5em; |
| 179 | } |
| 180 | div.admonitionblock td.content { |
| 181 | padding-left: 0.5em; |
| 182 | border-left: 2px solid silver; |
| 183 | } |
| 184 | |
| 185 | div.exampleblock > div.content { |
| 186 | border-left: 2px solid silver; |
| 187 | padding: 0.5em; |
| 188 | } |
| 189 | |
| 190 | div.verseblock div.content { |
| 191 | white-space: pre; |
| 192 | } |
| 193 | |
| 194 | div.imageblock div.content { padding-left: 0; } |
| 195 | div.imageblock img { border: 1px solid silver; } |
| 196 | span.image img { border-style: none; } |
| 197 | |
| 198 | dl { |
| 199 | margin-top: 0.8em; |
| 200 | margin-bottom: 0.8em; |
| 201 | } |
| 202 | dt { |
| 203 | margin-top: 0.5em; |
| 204 | margin-bottom: 0; |
| 205 | font-style: italic; |
| 206 | } |
| 207 | dd > *:first-child { |
| 208 | margin-top: 0; |
| 209 | } |
| 210 | |
| 211 | ul, ol { |
| 212 | list-style-position: outside; |
| 213 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 214 | div.olist2 ol { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 215 | list-style-type: lower-alpha; |
| 216 | } |
| 217 | |
| 218 | div.tableblock > table { |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 219 | border: 3px solid #527bbd; |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 220 | } |
| 221 | thead { |
| 222 | font-family: sans-serif; |
| 223 | font-weight: bold; |
| 224 | } |
| 225 | tfoot { |
| 226 | font-weight: bold; |
| 227 | } |
| 228 | |
| 229 | div.hlist { |
| 230 | margin-top: 0.8em; |
| 231 | margin-bottom: 0.8em; |
| 232 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 233 | div.hlist td { |
| 234 | padding-bottom: 5px; |
| 235 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 236 | td.hlist1 { |
| 237 | vertical-align: top; |
| 238 | font-style: italic; |
| 239 | padding-right: 0.8em; |
| 240 | } |
| 241 | td.hlist2 { |
| 242 | vertical-align: top; |
| 243 | } |
| 244 | |
| 245 | @media print { |
| 246 | div#footer-badges { display: none; } |
| 247 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 248 | |
| 249 | div#toctitle { |
| 250 | color: #527bbd; |
| 251 | font-family: sans-serif; |
| 252 | font-size: 1.1em; |
| 253 | font-weight: bold; |
| 254 | margin-top: 1.0em; |
| 255 | margin-bottom: 0.1em; |
| 256 | } |
| 257 | |
| 258 | div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 259 | margin-top: 0; |
| 260 | margin-bottom: 0; |
| 261 | } |
| 262 | div.toclevel2 { |
| 263 | margin-left: 2em; |
| 264 | font-size: 0.9em; |
| 265 | } |
| 266 | div.toclevel3 { |
| 267 | margin-left: 4em; |
| 268 | font-size: 0.9em; |
| 269 | } |
| 270 | div.toclevel4 { |
| 271 | margin-left: 6em; |
| 272 | font-size: 0.9em; |
| 273 | } |
| 274 | include1::./stylesheets/xhtml11-manpage.css[] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 275 | /* Workarounds for IE6's broken and incomplete CSS2. */ |
| 276 | |
| 277 | div.sidebar-content { |
| 278 | background: #ffffee; |
| 279 | border: 1px solid silver; |
| 280 | padding: 0.5em; |
| 281 | } |
| 282 | div.sidebar-title, div.image-title { |
| 283 | font-family: sans-serif; |
| 284 | font-weight: bold; |
| 285 | margin-top: 0.0em; |
| 286 | margin-bottom: 0.5em; |
| 287 | } |
| 288 | |
| 289 | div.listingblock div.content { |
| 290 | border: 1px solid silver; |
| 291 | background: #f4f4f4; |
| 292 | padding: 0.5em; |
| 293 | } |
| 294 | |
| 295 | div.quoteblock-content { |
| 296 | padding-left: 2.0em; |
| 297 | } |
| 298 | |
| 299 | div.exampleblock-content { |
| 300 | border-left: 2px solid silver; |
| 301 | padding-left: 0.5em; |
| 302 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 303 | |
| 304 | /* IE6 sets dynamically generated links as visited. */ |
| 305 | div#toc a:visited { color: blue; } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 306 | </style> |
| 307 | <title>git-reset(1)</title> |
| 308 | </head> |
| 309 | <body> |
| 310 | <div id="header"> |
| 311 | <h1> |
| 312 | git-reset(1) Manual Page |
| 313 | </h1> |
| 314 | <h2>NAME</h2> |
| 315 | <div class="sectionbody"> |
| 316 | <p>git-reset - |
Junio C Hamano | 0107892 | 2006-03-10 00:31:47 | [diff] [blame] | 317 | Reset current HEAD to the specified state |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 318 | </p> |
| 319 | </div> |
| 320 | </div> |
| 321 | <h2>SYNOPSIS</h2> |
| 322 | <div class="sectionbody"> |
Junio C Hamano | d793de5 | 2006-12-26 09:11:43 | [diff] [blame] | 323 | <div class="verseblock"> |
Junio C Hamano | bbbb865 | 2008-12-29 10:34:22 | [diff] [blame] | 324 | <div class="content"><em>git reset</em> [--mixed | --soft | --hard | --merge] [-q] [<commit>] |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 325 | <em>git reset</em> [-q] [<commit>] [--] <paths>… |
| 326 | <em>git reset</em> --patch [<commit>] [--] [<paths>…]</div></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 327 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 328 | <h2 id="_description">DESCRIPTION</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 329 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 330 | <div class="para"><p>Sets the current head to the specified commit and optionally resets the |
| 331 | index and working tree to match.</p></div> |
| 332 | <div class="para"><p>This command is useful if you notice some small error in a recent |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 333 | commit (or set of commits) and want to redo that part without showing |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 334 | the undo in the history.</p></div> |
| 335 | <div class="para"><p>If you want to undo a commit other than the latest on a branch, |
| 336 | <a href="git-revert.html">git-revert(1)</a> is your friend.</p></div> |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 337 | <div class="para"><p>The second and third forms with <em>paths</em> and/or --patch are used to |
| 338 | revert selected paths in the index from a given commit, without moving |
| 339 | HEAD.</p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 340 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 341 | <h2 id="_options">OPTIONS</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 342 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 343 | <div class="vlist"><dl> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 344 | <dt> |
| 345 | --mixed |
| 346 | </dt> |
| 347 | <dd> |
| 348 | <p> |
Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 349 | Resets the index but not the working tree (i.e., the changed files |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 350 | are preserved but not marked for commit) and reports what has not |
| 351 | been updated. This is the default action. |
| 352 | </p> |
| 353 | </dd> |
| 354 | <dt> |
| 355 | --soft |
| 356 | </dt> |
| 357 | <dd> |
| 358 | <p> |
| 359 | Does not touch the index file nor the working tree at all, but |
| 360 | requires them to be in a good order. This leaves all your changed |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 361 | files "Changes to be committed", as <em>git-status</em> would |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 362 | put it. |
| 363 | </p> |
| 364 | </dd> |
| 365 | <dt> |
| 366 | --hard |
| 367 | </dt> |
| 368 | <dd> |
| 369 | <p> |
| 370 | Matches the working tree and index to that of the tree being |
| 371 | switched to. Any changes to tracked files in the working tree |
Junio C Hamano | d793de5 | 2006-12-26 09:11:43 | [diff] [blame] | 372 | since <commit> are lost. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 373 | </p> |
| 374 | </dd> |
| 375 | <dt> |
Junio C Hamano | bbbb865 | 2008-12-29 10:34:22 | [diff] [blame] | 376 | --merge |
| 377 | </dt> |
| 378 | <dd> |
| 379 | <p> |
| 380 | Resets the index to match the tree recorded by the named commit, |
| 381 | and updates the files that are different between the named commit |
| 382 | and the current commit in the working tree. |
| 383 | </p> |
| 384 | </dd> |
| 385 | <dt> |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 386 | -p |
| 387 | </dt> |
| 388 | <dt> |
| 389 | --patch |
| 390 | </dt> |
| 391 | <dd> |
| 392 | <p> |
| 393 | Interactively select hunks in the difference between the index |
| 394 | and <commit> (defaults to HEAD). The chosen hunks are applied |
| 395 | in reverse to the index. |
| 396 | </p> |
| 397 | <div class="para"><p>This means that <tt>git reset -p</tt> is the opposite of <tt>git add -p</tt> (see |
| 398 | <a href="git-add.html">git-add(1)</a>).</p></div> |
| 399 | </dd> |
| 400 | <dt> |
Junio C Hamano | 422cfec | 2007-11-08 08:07:45 | [diff] [blame] | 401 | -q |
| 402 | </dt> |
Junio C Hamano | b141a92 | 2010-01-10 19:55:14 | [diff] [blame^] | 403 | <dt> |
| 404 | --quiet |
| 405 | </dt> |
Junio C Hamano | 422cfec | 2007-11-08 08:07:45 | [diff] [blame] | 406 | <dd> |
| 407 | <p> |
| 408 | Be quiet, only report errors. |
| 409 | </p> |
| 410 | </dd> |
| 411 | <dt> |
Junio C Hamano | d793de5 | 2006-12-26 09:11:43 | [diff] [blame] | 412 | <commit> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 413 | </dt> |
| 414 | <dd> |
| 415 | <p> |
Junio C Hamano | 14b7648 | 2008-01-05 10:32:26 | [diff] [blame] | 416 | Commit to make the current HEAD. If not given defaults to HEAD. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 417 | </p> |
| 418 | </dd> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 419 | </dl></div> |
Junio C Hamano | 1bb569e | 2006-05-05 23:14:25 | [diff] [blame] | 420 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 421 | <h2 id="_examples">Examples</h2> |
Junio C Hamano | 1bb569e | 2006-05-05 23:14:25 | [diff] [blame] | 422 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 423 | <div class="vlist"><dl> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 424 | <dt> |
| 425 | Undo a commit and redo |
| 426 | </dt> |
| 427 | <dd> |
| 428 | <div class="listingblock"> |
| 429 | <div class="content"> |
| 430 | <pre><tt>$ git commit ... |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 431 | $ git reset --soft HEAD^ <b>(1)</b> |
| 432 | $ edit <b>(2)</b> |
| 433 | $ git commit -a -c ORIG_HEAD <b>(3)</b></tt></pre> |
| 434 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 435 | <div class="colist"><ol> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 436 | <li> |
| 437 | <p> |
| 438 | This is most often done when you remembered what you |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 439 | just committed is incomplete, or you misspelled your commit |
| 440 | message, or both. Leaves working tree as it was before "reset". |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 441 | </p> |
| 442 | </li> |
| 443 | <li> |
| 444 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 445 | Make corrections to working tree files. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 446 | </p> |
| 447 | </li> |
| 448 | <li> |
| 449 | <p> |
| 450 | "reset" copies the old head to .git/ORIG_HEAD; redo the |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 451 | commit by starting with its log message. If you do not need to |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 452 | edit the message further, you can give -C option instead. |
| 453 | </p> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 454 | <div class="para"><p>See also the --amend option to <a href="git-commit.html">git-commit(1)</a>.</p></div> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 455 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 456 | </ol></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 457 | </dd> |
| 458 | <dt> |
| 459 | Undo commits permanently |
| 460 | </dt> |
| 461 | <dd> |
| 462 | <div class="listingblock"> |
| 463 | <div class="content"> |
| 464 | <pre><tt>$ git commit ... |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 465 | $ git reset --hard HEAD~3 <b>(1)</b></tt></pre> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 466 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 467 | <div class="colist"><ol> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 468 | <li> |
| 469 | <p> |
| 470 | The last three commits (HEAD, HEAD^, and HEAD~2) were bad |
| 471 | and you do not want to ever see them again. Do <strong>not</strong> do this if |
Junio C Hamano | 7d06a8a | 2008-10-20 05:42:33 | [diff] [blame] | 472 | you have already given these commits to somebody else. (See the |
| 473 | "RECOVERING FROM UPSTREAM REBASE" section in <a href="git-rebase.html">git-rebase(1)</a> for |
| 474 | the implications of doing so.) |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 475 | </p> |
| 476 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 477 | </ol></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 478 | </dd> |
| 479 | <dt> |
| 480 | Undo a commit, making it a topic branch |
| 481 | </dt> |
| 482 | <dd> |
| 483 | <div class="listingblock"> |
| 484 | <div class="content"> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 485 | <pre><tt>$ git branch topic/wip <b>(1)</b> |
| 486 | $ git reset --hard HEAD~3 <b>(2)</b> |
| 487 | $ git checkout topic/wip <b>(3)</b></tt></pre> |
| 488 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 489 | <div class="colist"><ol> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 490 | <li> |
| 491 | <p> |
| 492 | You have made some commits, but realize they were premature |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 493 | to be in the "master" branch. You want to continue polishing |
| 494 | them in a topic branch, so create "topic/wip" branch off of the |
| 495 | current HEAD. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 496 | </p> |
| 497 | </li> |
| 498 | <li> |
| 499 | <p> |
| 500 | Rewind the master branch to get rid of those three commits. |
| 501 | </p> |
| 502 | </li> |
| 503 | <li> |
| 504 | <p> |
| 505 | Switch to "topic/wip" branch and keep working. |
| 506 | </p> |
| 507 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 508 | </ol></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 509 | </dd> |
| 510 | <dt> |
Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 511 | Undo add |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 512 | </dt> |
| 513 | <dd> |
| 514 | <div class="listingblock"> |
| 515 | <div class="content"> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 516 | <pre><tt>$ edit <b>(1)</b> |
Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 517 | $ git add frotz.c filfre.c |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 518 | $ mailx <b>(2)</b> |
| 519 | $ git reset <b>(3)</b> |
| 520 | $ git pull git://info.example.com/ nitfol <b>(4)</b></tt></pre> |
| 521 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 522 | <div class="colist"><ol> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 523 | <li> |
| 524 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 525 | You are happily working on something, and find the changes |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 526 | in these files are in good order. You do not want to see them |
| 527 | when you run "git diff", because you plan to work on other files |
| 528 | and changes with these files are distracting. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 529 | </p> |
| 530 | </li> |
| 531 | <li> |
| 532 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 533 | Somebody asks you to pull, and the changes sounds worthy of merging. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 534 | </p> |
| 535 | </li> |
| 536 | <li> |
| 537 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 538 | However, you already dirtied the index (i.e. your index does |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 539 | not match the HEAD commit). But you know the pull you are going |
| 540 | to make does not affect frotz.c nor filfre.c, so you revert the |
| 541 | index changes for these two files. Your changes in working tree |
| 542 | remain there. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 543 | </p> |
| 544 | </li> |
| 545 | <li> |
| 546 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 547 | Then you can pull and merge, leaving frotz.c and filfre.c |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 548 | changes still in the working tree. |
| 549 | </p> |
| 550 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 551 | </ol></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 552 | </dd> |
| 553 | <dt> |
| 554 | Undo a merge or pull |
| 555 | </dt> |
| 556 | <dd> |
| 557 | <div class="listingblock"> |
| 558 | <div class="content"> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 559 | <pre><tt>$ git pull <b>(1)</b> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 560 | Auto-merging nitfol |
| 561 | CONFLICT (content): Merge conflict in nitfol |
Junio C Hamano | 6a3c827 | 2008-12-19 21:38:18 | [diff] [blame] | 562 | Automatic merge failed; fix conflicts and then commit the result. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 563 | $ git reset --hard <b>(2)</b> |
| 564 | $ git pull . topic/branch <b>(3)</b> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 565 | Updating from 41223... to 13134... |
Junio C Hamano | 3f680f3 | 2009-11-16 02:10:54 | [diff] [blame] | 566 | Fast-forward |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 567 | $ git reset --hard ORIG_HEAD <b>(4)</b></tt></pre> |
| 568 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 569 | <div class="colist"><ol> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 570 | <li> |
| 571 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 572 | Try to update from the upstream resulted in a lot of |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 573 | conflicts; you were not ready to spend a lot of time merging |
| 574 | right now, so you decide to do that later. |
| 575 | </p> |
| 576 | </li> |
| 577 | <li> |
| 578 | <p> |
| 579 | "pull" has not made merge commit, so "git reset --hard" |
| 580 | which is a synonym for "git reset --hard HEAD" clears the mess |
| 581 | from the index file and the working tree. |
| 582 | </p> |
| 583 | </li> |
| 584 | <li> |
| 585 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 586 | Merge a topic branch into the current branch, which resulted |
Junio C Hamano | 3f680f3 | 2009-11-16 02:10:54 | [diff] [blame] | 587 | in a fast-forward. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 588 | </p> |
| 589 | </li> |
| 590 | <li> |
| 591 | <p> |
Junio C Hamano | 092f5f0 | 2007-08-02 07:23:38 | [diff] [blame] | 592 | But you decided that the topic branch is not ready for public |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 593 | consumption yet. "pull" or "merge" always leaves the original |
| 594 | tip of the current branch in ORIG_HEAD, so resetting hard to it |
| 595 | brings your index file and the working tree back to that state, |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 596 | and resets the tip of the branch to that commit. |
| 597 | </p> |
| 598 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 599 | </ol></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 600 | </dd> |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 601 | <dt> |
Junio C Hamano | bbbb865 | 2008-12-29 10:34:22 | [diff] [blame] | 602 | Undo a merge or pull inside a dirty work tree |
| 603 | </dt> |
| 604 | <dd> |
| 605 | <div class="listingblock"> |
| 606 | <div class="content"> |
| 607 | <pre><tt>$ git pull <b>(1)</b> |
| 608 | Auto-merging nitfol |
| 609 | Merge made by recursive. |
| 610 | nitfol | 20 +++++---- |
| 611 | ... |
| 612 | $ git reset --merge ORIG_HEAD <b>(2)</b></tt></pre> |
| 613 | </div></div> |
| 614 | <div class="colist"><ol> |
| 615 | <li> |
| 616 | <p> |
| 617 | Even if you may have local modifications in your |
| 618 | working tree, you can safely say "git pull" when you know |
| 619 | that the change in the other branch does not overlap with |
| 620 | them. |
| 621 | </p> |
| 622 | </li> |
| 623 | <li> |
| 624 | <p> |
| 625 | After inspecting the result of the merge, you may find |
| 626 | that the change in the other branch is unsatisfactory. Running |
| 627 | "git reset --hard ORIG_HEAD" will let you go back to where you |
| 628 | were, but it will discard your local changes, which you do not |
| 629 | want. "git reset --merge" keeps your local changes. |
| 630 | </p> |
| 631 | </li> |
| 632 | </ol></div> |
| 633 | </dd> |
| 634 | <dt> |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 635 | Interrupted workflow |
| 636 | </dt> |
| 637 | <dd> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 638 | <div class="para"><p>Suppose you are interrupted by an urgent fix request while you |
Junio C Hamano | a6331a8 | 2006-01-22 07:50:33 | [diff] [blame] | 639 | are in the middle of a large change. The files in your |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 640 | working tree are not in any shape to be committed yet, but you |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 641 | need to get to the other branch for a quick bugfix.</p></div> |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 642 | <div class="listingblock"> |
| 643 | <div class="content"> |
| 644 | <pre><tt>$ git checkout feature ;# you were working in "feature" branch and |
| 645 | $ work work work ;# got interrupted |
Junio C Hamano | 7ae0ab2 | 2007-11-03 02:46:46 | [diff] [blame] | 646 | $ git commit -a -m "snapshot WIP" <b>(1)</b> |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 647 | $ git checkout master |
| 648 | $ fix fix fix |
| 649 | $ git commit ;# commit with real log |
| 650 | $ git checkout feature |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 651 | $ git reset --soft HEAD^ ;# go back to WIP state <b>(2)</b> |
| 652 | $ git reset <b>(3)</b></tt></pre> |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 653 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 654 | <div class="colist"><ol> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 655 | <li> |
| 656 | <p> |
| 657 | This commit will get blown away so a throw-away log message is OK. |
| 658 | </p> |
| 659 | </li> |
| 660 | <li> |
| 661 | <p> |
| 662 | This removes the <em>WIP</em> commit from the commit history, and sets |
| 663 | your working tree to the state just before you made that snapshot. |
| 664 | </p> |
| 665 | </li> |
| 666 | <li> |
| 667 | <p> |
| 668 | At this point the index file still has all the WIP changes you |
| 669 | committed as <em>snapshot WIP</em>. This updates the index to show your |
| 670 | WIP files as uncommitted. |
| 671 | </p> |
Junio C Hamano | 116db35 | 2008-12-17 19:48:40 | [diff] [blame] | 672 | <div class="para"><p>See also <a href="git-stash.html">git-stash(1)</a>.</p></div> |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 673 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 674 | </ol></div> |
Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 675 | </dd> |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 676 | <dt> |
| 677 | Reset a single file in the index |
| 678 | </dt> |
| 679 | <dd> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 680 | <div class="para"><p>Suppose you have added a file to your index, but later decide you do not |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 681 | want to add it to your commit. You can remove the file from the index |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 682 | while keeping your changes with git reset.</p></div> |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 683 | <div class="listingblock"> |
| 684 | <div class="content"> |
| 685 | <pre><tt>$ git reset -- frotz.c <b>(1)</b> |
| 686 | $ git commit -m "Commit files in index" <b>(2)</b> |
| 687 | $ git add frotz.c <b>(3)</b></tt></pre> |
| 688 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 689 | <div class="colist"><ol> |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 690 | <li> |
| 691 | <p> |
| 692 | This removes the file from the index while keeping it in the working |
| 693 | directory. |
| 694 | </p> |
| 695 | </li> |
| 696 | <li> |
| 697 | <p> |
| 698 | This commits all other changes in the index. |
| 699 | </p> |
| 700 | </li> |
| 701 | <li> |
| 702 | <p> |
| 703 | Adds the file to the index again. |
| 704 | </p> |
| 705 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 706 | </ol></div> |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 707 | </dd> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 708 | </dl></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 709 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 710 | <h2 id="_author">Author</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 711 | <div class="sectionbody"> |
Junio C Hamano | 0868a30 | 2008-07-22 09:20:44 | [diff] [blame] | 712 | <div class="para"><p>Written by Junio C Hamano <gitster@pobox.com> and Linus Torvalds <torvalds@osdl.org></p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 713 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 714 | <h2 id="_documentation">Documentation</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 715 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 716 | <div class="para"><p>Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.</p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 717 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 718 | <h2 id="_git">GIT</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 719 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 720 | <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 721 | </div> |
| 722 | <div id="footer"> |
| 723 | <div id="footer-text"> |
Junio C Hamano | b141a92 | 2010-01-10 19:55:14 | [diff] [blame^] | 724 | Last updated 2010-01-10 19:52:59 UTC |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 725 | </div> |
| 726 | </div> |
| 727 | </body> |
| 728 | </html> |