Autogenerated HTML docs for v1.7.4-rc2
[git/jnareb-git.git] / git-stash.html
bloba720fe6287bf9796367eed671016044e41c4f5be
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" />
6 <meta name="generator" content="AsciiDoc 8.2.5" />
7 <style type="text/css">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
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;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
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;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
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;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
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;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
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;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
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;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
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;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>git-stash(1)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 git-stash(1) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>git-stash -
317 Stash the changes in a dirty working directory away
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="verseblock">
324 <div class="content"><em>git stash</em> list [&lt;options&gt;]
325 <em>git stash</em> show [&lt;stash&gt;]
326 <em>git stash</em> drop [-q|--quiet] [&lt;stash&gt;]
327 <em>git stash</em> ( pop | apply ) [--index] [-q|--quiet] [&lt;stash&gt;]
328 <em>git stash</em> branch &lt;branchname&gt; [&lt;stash&gt;]
329 <em>git stash</em> [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] [&lt;message&gt;]]
330 <em>git stash</em> clear
331 <em>git stash</em> create</div></div>
332 </div>
333 <h2 id="_description">DESCRIPTION</h2>
334 <div class="sectionbody">
335 <div class="para"><p>Use <tt>git stash</tt> when you want to record the current state of the
336 working directory and the index, but want to go back to a clean
337 working directory. The command saves your local modifications away
338 and reverts the working directory to match the <tt>HEAD</tt> commit.</p></div>
339 <div class="para"><p>The modifications stashed away by this command can be listed with
340 <tt>git stash list</tt>, inspected with <tt>git stash show</tt>, and restored
341 (potentially on top of a different commit) with <tt>git stash apply</tt>.
342 Calling <tt>git stash</tt> without any arguments is equivalent to <tt>git stash save</tt>.
343 A stash is by default listed as "WIP on <em>branchname</em> &#8230;", but
344 you can give a more descriptive message on the command line when
345 you create one.</p></div>
346 <div class="para"><p>The latest stash you created is stored in <tt>refs/stash</tt>; older
347 stashes are found in the reflog of this reference and can be named using
348 the usual reflog syntax (e.g. <tt>stash@{0}</tt> is the most recently
349 created stash, <tt>stash@{1}</tt> is the one before it, <tt>stash@{2.hours.ago}</tt>
350 is also possible).</p></div>
351 </div>
352 <h2 id="_options">OPTIONS</h2>
353 <div class="sectionbody">
354 <div class="vlist"><dl>
355 <dt>
356 save [--patch] [--[no-]keep-index] [-q|--quiet] [&lt;message&gt;]
357 </dt>
358 <dd>
360 Save your local modifications to a new <em>stash</em>, and run <tt>git reset
361 --hard</tt> to revert them. The &lt;message&gt; part is optional and gives
362 the description along with the stashed state. For quickly making
363 a snapshot, you can omit _both_ "save" and &lt;message&gt;, but giving
364 only &lt;message&gt; does not trigger this action to prevent a misspelled
365 subcommand from making an unwanted stash.
366 </p>
367 <div class="para"><p>If the <tt>--keep-index</tt> option is used, all changes already added to the
368 index are left intact.</p></div>
369 <div class="para"><p>With <tt>--patch</tt>, you can interactively select hunks from in the diff
370 between HEAD and the working tree to be stashed. The stash entry is
371 constructed such that its index state is the same as the index state
372 of your repository, and its worktree contains only the changes you
373 selected interactively. The selected changes are then rolled back
374 from your worktree.</p></div>
375 <div class="para"><p>The <tt>--patch</tt> option implies <tt>--keep-index</tt>. You can use
376 <tt>--no-keep-index</tt> to override this.</p></div>
377 </dd>
378 <dt>
379 list [&lt;options&gt;]
380 </dt>
381 <dd>
383 List the stashes that you currently have. Each <em>stash</em> is listed
384 with its name (e.g. <tt>stash@{0}</tt> is the latest stash, <tt>stash@{1}</tt> is
385 the one before, etc.), the name of the branch that was current when the
386 stash was made, and a short description of the commit the stash was
387 based on.
388 </p>
389 <div class="listingblock">
390 <div class="content">
391 <pre><tt>stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
392 stash@{1}: On master: 9cc0589... Add git-stash</tt></pre>
393 </div></div>
394 <div class="para"><p>The command takes options applicable to the <em>git log</em>
395 command to control what is shown and how. See <a href="git-log.html">git-log(1)</a>.</p></div>
396 </dd>
397 <dt>
398 show [&lt;stash&gt;]
399 </dt>
400 <dd>
402 Show the changes recorded in the stash as a diff between the
403 stashed state and its original parent. When no <tt>&lt;stash&gt;</tt> is given,
404 shows the latest one. By default, the command shows the diffstat, but
405 it will accept any format known to <em>git diff</em> (e.g., <tt>git stash show
406 -p stash@{1}</tt> to view the second most recent stash in patch form).
407 </p>
408 </dd>
409 <dt>
410 pop [--index] [-q|--quiet] [&lt;stash&gt;]
411 </dt>
412 <dd>
414 Remove a single stashed state from the stash list and apply it
415 on top of the current working tree state, i.e., do the inverse
416 operation of <tt>git stash save</tt>. The working directory must
417 match the index.
418 </p>
419 <div class="para"><p>Applying the state can fail with conflicts; in this case, it is not
420 removed from the stash list. You need to resolve the conflicts by hand
421 and call <tt>git stash drop</tt> manually afterwards.</p></div>
422 <div class="para"><p>If the <tt>--index</tt> option is used, then tries to reinstate not only the working
423 tree's changes, but also the index's ones. However, this can fail, when you
424 have conflicts (which are stored in the index, where you therefore can no
425 longer apply the changes as they were originally).</p></div>
426 <div class="para"><p>When no <tt>&lt;stash&gt;</tt> is given, <tt>stash@{0}</tt> is assumed, otherwise <tt>&lt;stash&gt;</tt> must
427 be a reference of the form <tt>stash@{&lt;revision&gt;}</tt>.</p></div>
428 </dd>
429 <dt>
430 apply [--index] [-q|--quiet] [&lt;stash&gt;]
431 </dt>
432 <dd>
434 Like <tt>pop</tt>, but do not remove the state from the stash list. Unlike <tt>pop</tt>,
435 <tt>&lt;stash&gt;</tt> may be any commit that looks like a commit created by
436 <tt>stash save</tt> or <tt>stash create</tt>.
437 </p>
438 </dd>
439 <dt>
440 branch &lt;branchname&gt; [&lt;stash&gt;]
441 </dt>
442 <dd>
444 Creates and checks out a new branch named <tt>&lt;branchname&gt;</tt> starting from
445 the commit at which the <tt>&lt;stash&gt;</tt> was originally created, applies the
446 changes recorded in <tt>&lt;stash&gt;</tt> to the new working tree and index.
447 If that succeeds, and <tt>&lt;stash&gt;</tt> is a reference of the form
448 <tt>stash@{&lt;revision&gt;}</tt>, it then drops the <tt>&lt;stash&gt;</tt>. When no <tt>&lt;stash&gt;</tt>
449 is given, applies the latest one.
450 </p>
451 <div class="para"><p>This is useful if the branch on which you ran <tt>git stash save</tt> has
452 changed enough that <tt>git stash apply</tt> fails due to conflicts. Since
453 the stash is applied on top of the commit that was HEAD at the time
454 <tt>git stash</tt> was run, it restores the originally stashed state with
455 no conflicts.</p></div>
456 </dd>
457 <dt>
458 clear
459 </dt>
460 <dd>
462 Remove all the stashed states. Note that those states will then
463 be subject to pruning, and may be impossible to recover (see
464 <em>Examples</em> below for a possible strategy).
465 </p>
466 </dd>
467 <dt>
468 drop [-q|--quiet] [&lt;stash&gt;]
469 </dt>
470 <dd>
472 Remove a single stashed state from the stash list. When no <tt>&lt;stash&gt;</tt>
473 is given, it removes the latest one. i.e. <tt>stash@{0}</tt>, otherwise
474 <tt>&lt;stash&gt;</tt> must a valid stash log reference of the form
475 <tt>stash@{&lt;revision&gt;}</tt>.
476 </p>
477 </dd>
478 <dt>
479 create
480 </dt>
481 <dd>
483 Create a stash (which is a regular commit object) and return its
484 object name, without storing it anywhere in the ref namespace.
485 </p>
486 </dd>
487 </dl></div>
488 </div>
489 <h2 id="_discussion">DISCUSSION</h2>
490 <div class="sectionbody">
491 <div class="para"><p>A stash is represented as a commit whose tree records the state of the
492 working directory, and its first parent is the commit at <tt>HEAD</tt> when
493 the stash was created. The tree of the second parent records the
494 state of the index when the stash is made, and it is made a child of
495 the <tt>HEAD</tt> commit. The ancestry graph looks like this:</p></div>
496 <div class="literalblock">
497 <div class="content">
498 <pre><tt> .----W
500 -----H----I</tt></pre>
501 </div></div>
502 <div class="para"><p>where <tt>H</tt> is the <tt>HEAD</tt> commit, <tt>I</tt> is a commit that records the state
503 of the index, and <tt>W</tt> is a commit that records the state of the working
504 tree.</p></div>
505 </div>
506 <h2 id="_examples">EXAMPLES</h2>
507 <div class="sectionbody">
508 <div class="vlist"><dl>
509 <dt>
510 Pulling into a dirty tree
511 </dt>
512 <dd>
514 When you are in the middle of something, you learn that there are
515 upstream changes that are possibly relevant to what you are
516 doing. When your local changes do not conflict with the changes in
517 the upstream, a simple <tt>git pull</tt> will let you move forward.
518 </p>
519 <div class="para"><p>However, there are cases in which your local changes do conflict with
520 the upstream changes, and <tt>git pull</tt> refuses to overwrite your
521 changes. In such a case, you can stash your changes away,
522 perform a pull, and then unstash, like this:</p></div>
523 <div class="listingblock">
524 <div class="content">
525 <pre><tt>$ git pull
527 file foobar not up to date, cannot merge.
528 $ git stash
529 $ git pull
530 $ git stash pop</tt></pre>
531 </div></div>
532 </dd>
533 <dt>
534 Interrupted workflow
535 </dt>
536 <dd>
538 When you are in the middle of something, your boss comes in and
539 demands that you fix something immediately. Traditionally, you would
540 make a commit to a temporary branch to store your changes away, and
541 return to your original branch to make the emergency fix, like this:
542 </p>
543 <div class="listingblock">
544 <div class="content">
545 <pre><tt># ... hack hack hack ...
546 $ git checkout -b my_wip
547 $ git commit -a -m "WIP"
548 $ git checkout master
549 $ edit emergency fix
550 $ git commit -a -m "Fix in a hurry"
551 $ git checkout my_wip
552 $ git reset --soft HEAD^
553 # ... continue hacking ...</tt></pre>
554 </div></div>
555 <div class="para"><p>You can use <em>git stash</em> to simplify the above, like this:</p></div>
556 <div class="listingblock">
557 <div class="content">
558 <pre><tt># ... hack hack hack ...
559 $ git stash
560 $ edit emergency fix
561 $ git commit -a -m "Fix in a hurry"
562 $ git stash pop
563 # ... continue hacking ...</tt></pre>
564 </div></div>
565 </dd>
566 <dt>
567 Testing partial commits
568 </dt>
569 <dd>
571 You can use <tt>git stash save --keep-index</tt> when you want to make two or
572 more commits out of the changes in the work tree, and you want to test
573 each change before committing:
574 </p>
575 <div class="listingblock">
576 <div class="content">
577 <pre><tt># ... hack hack hack ...
578 $ git add --patch foo # add just first part to the index
579 $ git stash save --keep-index # save all other changes to the stash
580 $ edit/build/test first part
581 $ git commit -m 'First part' # commit fully tested change
582 $ git stash pop # prepare to work on all other changes
583 # ... repeat above five steps until one commit remains ...
584 $ edit/build/test remaining parts
585 $ git commit foo -m 'Remaining parts'</tt></pre>
586 </div></div>
587 </dd>
588 <dt>
589 Recovering stashes that were cleared/dropped erroneously
590 </dt>
591 <dd>
593 If you mistakenly drop or clear stashes, they cannot be recovered
594 through the normal safety mechanisms. However, you can try the
595 following incantation to get a list of stashes that are still in your
596 repository, but not reachable any more:
597 </p>
598 <div class="listingblock">
599 <div class="content">
600 <pre><tt>git fsck --unreachable |
601 grep commit | cut -d\ -f3 |
602 xargs git log --merges --no-walk --grep=WIP</tt></pre>
603 </div></div>
604 </dd>
605 </dl></div>
606 </div>
607 <h2 id="_see_also">SEE ALSO</h2>
608 <div class="sectionbody">
609 <div class="para"><p><a href="git-checkout.html">git-checkout(1)</a>,
610 <a href="git-commit.html">git-commit(1)</a>,
611 <a href="git-reflog.html">git-reflog(1)</a>,
612 <a href="git-reset.html">git-reset(1)</a></p></div>
613 </div>
614 <h2 id="_author">AUTHOR</h2>
615 <div class="sectionbody">
616 <div class="para"><p>Written by Nanako Shiraishi &lt;nanako3@bluebottle.com&gt;</p></div>
617 </div>
618 <h2 id="_git">GIT</h2>
619 <div class="sectionbody">
620 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
621 </div>
622 <div id="footer">
623 <div id="footer-text">
624 Last updated 2010-09-18 23:56:58 UTC
625 </div>
626 </div>
627 </body>
628 </html>