05f40cff6cbaa9d8a08176a5a601b7e43d17e5bf
   1git-stash(1)
   2============
   3
   4NAME
   5----
   6git-stash - Stash the changes in a dirty working directory away
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git-stash' (list | show [<stash>] | apply [<stash>] | clear)
  12'git-stash' [save] [message...]
  13
  14DESCRIPTION
  15-----------
  16
  17Use 'git-stash' when you want to record the current state of the
  18working directory and the index, but want to go back to a clean
  19working directory.  The command saves your local modifications away
  20and reverts the working directory to match the `HEAD` commit.
  21
  22The modifications stashed away by this command can be listed with
  23`git-stash list`, inspected with `git-stash show`, and restored
  24(potentially on top of a different commit) with `git-stash apply`.
  25Calling git-stash without any arguments is equivalent to `git-stash
  26save`.  A stash is by default listed as "WIP on 'branchname' ...", but
  27you can give a more descriptive message on the command line when
  28you create one.
  29
  30The latest stash you created is stored in `$GIT_DIR/refs/stash`; older
  31stashes are found in the reflog of this reference and can be named using
  32the usual reflog syntax (e.g. `stash@\{0}` is the most recently
  33created stash, `stash@\{1}` is the one before it, `stash@\{2.hours.ago}`
  34is also possible).
  35
  36OPTIONS
  37-------
  38
  39save::
  40
  41        Save your local modifications to a new 'stash', and run `git-reset
  42        --hard` to revert them.  This is the default action when no
  43        subcommand is given.
  44
  45list::
  46
  47        List the stashes that you currently have.  Each 'stash' is listed
  48        with its name (e.g. `stash@\{0}` is the latest stash, `stash@\{1}` is
  49        the one before, etc.), the name of the branch that was current when the
  50        stash was made, and a short description of the commit the stash was
  51        based on.
  52+
  53----------------------------------------------------------------
  54stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
  55stash@{1}: On master: 9cc0589... Add git-stash
  56----------------------------------------------------------------
  57
  58show [<stash>]::
  59
  60        Show the changes recorded in the stash as a diff between the the
  61        stashed state and its original parent. When no `<stash>` is given,
  62        shows the latest one. By default, the command shows the diffstat, but
  63        it will accept any format known to `git-diff` (e.g., `git-stash show
  64        -p stash@\{1}` to view the second most recent stash in patch form).
  65
  66apply [<stash>]::
  67
  68        Restore the changes recorded in the stash on top of the current
  69        working tree state.  When no `<stash>` is given, applies the latest
  70        one.  The working directory must match the index.
  71+
  72This operation can fail with conflicts; you need to resolve them
  73by hand in the working tree.
  74
  75clear::
  76        Remove all the stashed states. Note that those states will then
  77        be subject to pruning, and may be difficult or impossible to recover.
  78
  79
  80DISCUSSION
  81----------
  82
  83A stash is represented as a commit whose tree records the state of the
  84working directory, and its first parent is the commit at `HEAD` when
  85the stash was created.  The tree of the second parent records the
  86state of the index when the stash is made, and it is made a child of
  87the `HEAD` commit.  The ancestry graph looks like this:
  88
  89            .----W
  90           /    /
  91     -----H----I
  92
  93where `H` is the `HEAD` commit, `I` is a commit that records the state
  94of the index, and `W` is a commit that records the state of the working
  95tree.
  96
  97
  98EXAMPLES
  99--------
 100
 101Pulling into a dirty tree::
 102
 103When you are in the middle of something, you learn that there are
 104upstream changes that are possibly relevant to what you are
 105doing.  When your local changes do not conflict with the changes in
 106the upstream, a simple `git pull` will let you move forward.
 107+
 108However, there are cases in which your local changes do conflict with
 109the upstream changes, and `git pull` refuses to overwrite your
 110changes.  In such a case, you can stash your changes away,
 111perform a pull, and then unstash, like this:
 112+
 113----------------------------------------------------------------
 114$ git pull
 115...
 116file foobar not up to date, cannot merge.
 117$ git stash
 118$ git pull
 119$ git stash apply
 120----------------------------------------------------------------
 121
 122Interrupted workflow::
 123
 124When you are in the middle of something, your boss comes in and
 125demands that you fix something immediately.  Traditionally, you would
 126make a commit to a temporary branch to store your changes away, and
 127return to your original branch to make the emergency fix, like this:
 128+
 129----------------------------------------------------------------
 130... hack hack hack ...
 131$ git checkout -b my_wip
 132$ git commit -a -m "WIP"
 133$ git checkout master
 134$ edit emergency fix
 135$ git commit -a -m "Fix in a hurry"
 136$ git checkout my_wip
 137$ git reset --soft HEAD^
 138... continue hacking ...
 139----------------------------------------------------------------
 140+
 141You can use `git-stash` to simplify the above, like this:
 142+
 143----------------------------------------------------------------
 144... hack hack hack ...
 145$ git stash
 146$ edit emergency fix
 147$ git commit -a -m "Fix in a hurry"
 148$ git stash apply
 149... continue hacking ...
 150----------------------------------------------------------------
 151
 152SEE ALSO
 153--------
 154gitlink:git-checkout[1],
 155gitlink:git-commit[1],
 156gitlink:git-reflog[1],
 157gitlink:git-reset[1]
 158
 159AUTHOR
 160------
 161Written by Nanako Shiraishi <nanako3@bluebottle.com>
 162
 163GIT
 164---
 165Part of the gitlink:git[7] suite