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">
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">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
66 border: 1px solid silver
;
81 font-family: sans-serif
;
88 font-family: sans-serif
;
92 font-family: sans-serif
;
94 border-top: 2px solid silver
;
100 padding-bottom: 0.5em;
104 padding-bottom: 0.5em;
108 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
109 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
110 div
.admonitionblock
{
113 margin-bottom: 1.5em;
115 div
.admonitionblock
{
117 margin-bottom: 2.5em;
120 div
.content
{ /* Block element content. */
124 /* Block element titles. */
125 div
.title
, caption
.title
{
126 font-family: sans-serif
;
130 margin-bottom: 0.5em;
136 td div
.title:first-child
{
139 div
.content div
.title:first-child
{
142 div
.content
+ div
.title
{
146 div
.sidebarblock
> div
.content
{
148 border: 1px solid silver
;
155 div
.listingblock
> div
.content
{
156 border: 1px solid silver
;
161 div
.quoteblock
> div
.content
{
168 div
.verseblock
+ div
.attribution
{
172 div
.admonitionblock
.icon
{
176 text-decoration: underline
;
178 padding-right: 0.5em;
180 div
.admonitionblock td
.content
{
182 border-left: 2px solid silver
;
185 div
.exampleblock
> div
.content
{
186 border-left: 2px solid silver
;
190 div
.verseblock div
.content
{
194 div
.imageblock div
.content
{ padding-left: 0; }
195 div
.imageblock img
{ border: 1px solid silver
; }
196 span
.image img
{ border-style: none
; }
200 margin-bottom: 0.8em;
212 list-style-position: outside
;
215 list-style-type: lower-alpha
;
218 div
.tableblock
> table
{
219 border: 3px solid
#527bbd;
222 font-family: sans-serif
;
231 margin-bottom: 0.8em;
239 padding-right: 0.8em;
246 div#footer-badges
{ display: none
; }
251 font-family: sans-serif
;
255 margin-bottom: 0.1em;
258 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
274 include1::./stylesheets
/xhtml11-manpage
.css
[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div
.sidebar-content
{
279 border: 1px solid silver
;
282 div
.sidebar-title
, div
.image-title
{
283 font-family: sans-serif
;
286 margin-bottom: 0.5em;
289 div
.listingblock div
.content
{
290 border: 1px solid silver
;
295 div
.quoteblock-content
{
299 div
.exampleblock-content
{
300 border-left: 2px solid silver
;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc
a:visited
{ color: blue
; }
307 <title>git-stash(
1)
</title>
312 git-stash(
1) Manual Page
315 <div class=
"sectionbody">
317 Stash the changes in a dirty working directory away
322 <div class=
"sectionbody">
323 <div class=
"verseblock">
324 <div class=
"content"><em>git stash
</em> list [
<options
>]
325 <em>git stash
</em> show [
<stash
>]
326 <em>git stash
</em> drop [-q|--quiet] [
<stash
>]
327 <em>git stash
</em> ( pop | apply ) [--index] [-q|--quiet] [
<stash
>]
328 <em>git stash
</em> branch
<branchname
> [
<stash
>]
329 <em>git stash
</em> [save [--keep-index] [-q|--quiet] [
<message
>]]
330 <em>git stash
</em> clear
331 <em>git stash
</em> create
</div></div>
333 <h2 id=
"_description">DESCRIPTION
</h2>
334 <div class=
"sectionbody">
335 <div class=
"para"><p>Use
<em>git stash
</em> 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> …", 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>$GIT_DIR/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>
352 <h2 id=
"_options">OPTIONS
</h2>
353 <div class=
"sectionbody">
354 <div class=
"vlist"><dl>
356 save [--keep-index] [-q|--quiet] [
<message
>]
360 Save your local modifications to a new
<em>stash
</em>, and run
<tt>git reset
361 --hard
</tt> to revert them. This is the default action when no
362 subcommand is given. The
<message
> part is optional and gives
363 the description along with the stashed state.
365 <div class=
"para"><p>If the
<tt>--keep-index
</tt> option is used, all changes already added to the
366 index are left intact.
</p></div>
369 list [
<options
>]
373 List the stashes that you currently have. Each
<em>stash
</em> is listed
374 with its name (e.g.
<tt>stash@{
0}
</tt> is the latest stash,
<tt>stash@{
1}
</tt> is
375 the one before, etc.), the name of the branch that was current when the
376 stash was made, and a short description of the commit the stash was
379 <div class=
"listingblock">
380 <div class=
"content">
381 <pre><tt>stash@{
0}: WIP on submit:
6ebd0e2... Update git-stash documentation
382 stash@{
1}: On master:
9cc0589... Add git-stash
</tt></pre>
384 <div class=
"para"><p>The command takes options applicable to the
<em>git-log
</em>
385 command to control what is shown and how. See
<a href=
"git-log.html">git-log(
1)
</a>.
</p></div>
392 Show the changes recorded in the stash as a diff between the
393 stashed state and its original parent. When no
<tt><stash
></tt> is given,
394 shows the latest one. By default, the command shows the diffstat, but
395 it will accept any format known to
<em>git-diff
</em> (e.g.,
<tt>git stash show
396 -p stash@{
1}
</tt> to view the second most recent stash in patch form).
400 pop [--index] [-q|--quiet] [
<stash
>]
404 Remove a single stashed state from the stash list and apply it
405 on top of the current working tree state, i.e., do the inverse
406 operation of
<tt>git stash save
</tt>. The working directory must
409 <div class=
"para"><p>Applying the state can fail with conflicts; in this case, it is not
410 removed from the stash list. You need to resolve the conflicts by hand
411 and call
<tt>git stash drop
</tt> manually afterwards.
</p></div>
412 <div class=
"para"><p>If the
<tt>--index
</tt> option is used, then tries to reinstate not only the working
413 tree's changes, but also the index's ones. However, this can fail, when you
414 have conflicts (which are stored in the index, where you therefore can no
415 longer apply the changes as they were originally).
</p></div>
416 <div class=
"para"><p>When no
<tt><stash
></tt> is given,
<tt>stash@{
0}
</tt> is assumed.
</p></div>
419 apply [--index] [-q|--quiet] [
<stash
>]
423 Like
<tt>pop
</tt>, but do not remove the state from the stash list.
427 branch
<branchname
> [
<stash
>]
431 Creates and checks out a new branch named
<tt><branchname
></tt> starting from
432 the commit at which the
<tt><stash
></tt> was originally created, applies the
433 changes recorded in
<tt><stash
></tt> to the new working tree and index, then
434 drops the
<tt><stash
></tt> if that completes successfully. When no
<tt><stash
></tt>
435 is given, applies the latest one.
437 <div class=
"para"><p>This is useful if the branch on which you ran
<tt>git stash save
</tt> has
438 changed enough that
<tt>git stash apply
</tt> fails due to conflicts. Since
439 the stash is applied on top of the commit that was HEAD at the time
440 <tt>git stash
</tt> was run, it restores the originally stashed state with
441 no conflicts.
</p></div>
448 Remove all the stashed states. Note that those states will then
449 be subject to pruning, and may be difficult or impossible to recover.
453 drop [-q|--quiet] [
<stash
>]
457 Remove a single stashed state from the stash list. When no
<tt><stash
></tt>
458 is given, it removes the latest one. i.e.
<tt>stash@{
0}
</tt>
466 Create a stash (which is a regular commit object) and return its
467 object name, without storing it anywhere in the ref namespace.
472 <h2 id=
"_discussion">DISCUSSION
</h2>
473 <div class=
"sectionbody">
474 <div class=
"para"><p>A stash is represented as a commit whose tree records the state of the
475 working directory, and its first parent is the commit at
<tt>HEAD
</tt> when
476 the stash was created. The tree of the second parent records the
477 state of the index when the stash is made, and it is made a child of
478 the
<tt>HEAD
</tt> commit. The ancestry graph looks like this:
</p></div>
479 <div class=
"literalblock">
480 <div class=
"content">
483 -----H----I
</tt></pre>
485 <div class=
"para"><p>where
<tt>H
</tt> is the
<tt>HEAD
</tt> commit,
<tt>I
</tt> is a commit that records the state
486 of the index, and
<tt>W
</tt> is a commit that records the state of the working
489 <h2 id=
"_examples">EXAMPLES
</h2>
490 <div class=
"sectionbody">
491 <div class=
"vlist"><dl>
493 Pulling into a dirty tree
497 When you are in the middle of something, you learn that there are
498 upstream changes that are possibly relevant to what you are
499 doing. When your local changes do not conflict with the changes in
500 the upstream, a simple
<tt>git pull
</tt> will let you move forward.
502 <div class=
"para"><p>However, there are cases in which your local changes do conflict with
503 the upstream changes, and
<tt>git pull
</tt> refuses to overwrite your
504 changes. In such a case, you can stash your changes away,
505 perform a pull, and then unstash, like this:
</p></div>
506 <div class=
"listingblock">
507 <div class=
"content">
510 file foobar not up to date, cannot merge.
513 $ git stash pop
</tt></pre>
521 When you are in the middle of something, your boss comes in and
522 demands that you fix something immediately. Traditionally, you would
523 make a commit to a temporary branch to store your changes away, and
524 return to your original branch to make the emergency fix, like this:
526 <div class=
"listingblock">
527 <div class=
"content">
528 <pre><tt># ... hack hack hack ...
529 $ git checkout -b my_wip
530 $ git commit -a -m
"WIP"
531 $ git checkout master
533 $ git commit -a -m
"Fix in a hurry"
534 $ git checkout my_wip
535 $ git reset --soft HEAD^
536 # ... continue hacking ...
</tt></pre>
538 <div class=
"para"><p>You can use
<em>git-stash
</em> to simplify the above, like this:
</p></div>
539 <div class=
"listingblock">
540 <div class=
"content">
541 <pre><tt># ... hack hack hack ...
544 $ git commit -a -m
"Fix in a hurry"
546 # ... continue hacking ...
</tt></pre>
550 Testing partial commits
554 You can use
<tt>git stash save --keep-index
</tt> when you want to make two or
555 more commits out of the changes in the work tree, and you want to test
556 each change before committing:
558 <div class=
"listingblock">
559 <div class=
"content">
560 <pre><tt># ... hack hack hack ...
561 $ git add --patch foo # add just first part to the index
562 $ git stash save --keep-index # save all other changes to the stash
563 $ edit/build/test first part
564 $ git commit -m 'First part' # commit fully tested change
565 $ git stash pop # prepare to work on all other changes
566 # ... repeat above five steps until one commit remains ...
567 $ edit/build/test remaining parts
568 $ git commit foo -m 'Remaining parts'
</tt></pre>
573 <h2 id=
"_see_also">SEE ALSO
</h2>
574 <div class=
"sectionbody">
575 <div class=
"para"><p><a href=
"git-checkout.html">git-checkout(
1)
</a>,
576 <a href=
"git-commit.html">git-commit(
1)
</a>,
577 <a href=
"git-reflog.html">git-reflog(
1)
</a>,
578 <a href=
"git-reset.html">git-reset(
1)
</a></p></div>
580 <h2 id=
"_author">AUTHOR
</h2>
581 <div class=
"sectionbody">
582 <div class=
"para"><p>Written by Nanako Shiraishi
<nanako3@bluebottle.com
></p></div>
584 <h2 id=
"_git">GIT
</h2>
585 <div class=
"sectionbody">
586 <div class=
"para"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
589 <div id=
"footer-text">
590 Last updated
2009-
07-
02 03:
16:
40 UTC