Documentation / git-stash.txton commit git-p4: support exclude paths (354081d)
   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 [<message>]::
  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. The <message> part is optional and gives
  44        the description along with the stashed state.
  45
  46list [<options>]::
  47
  48        List the stashes that you currently have.  Each 'stash' is listed
  49        with its name (e.g. `stash@\{0}` is the latest stash, `stash@\{1}` is
  50        the one before, etc.), the name of the branch that was current when the
  51        stash was made, and a short description of the commit the stash was
  52        based on.
  53+
  54----------------------------------------------------------------
  55stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
  56stash@{1}: On master: 9cc0589... Add git-stash
  57----------------------------------------------------------------
  58+
  59The command takes options applicable to the linkgit:git-log[1]
  60command to control what is shown and how.
  61
  62show [<stash>]::
  63
  64        Show the changes recorded in the stash as a diff between the
  65        stashed state and its original parent. When no `<stash>` is given,
  66        shows the latest one. By default, the command shows the diffstat, but
  67        it will accept any format known to `git-diff` (e.g., `git-stash show
  68        -p stash@\{1}` to view the second most recent stash in patch form).
  69
  70apply [--index] [<stash>]::
  71
  72        Restore the changes recorded in the stash on top of the current
  73        working tree state.  When no `<stash>` is given, applies the latest
  74        one.  The working directory must match the index.
  75+
  76This operation can fail with conflicts; you need to resolve them
  77by hand in the working tree.
  78+
  79If the `--index` option is used, then tries to reinstate not only the working
  80tree's changes, but also the index's ones. However, this can fail, when you
  81have conflicts (which are stored in the index, where you therefore can no
  82longer apply the changes as they were originally).
  83
  84clear::
  85        Remove all the stashed states. Note that those states will then
  86        be subject to pruning, and may be difficult or impossible to recover.
  87
  88
  89DISCUSSION
  90----------
  91
  92A stash is represented as a commit whose tree records the state of the
  93working directory, and its first parent is the commit at `HEAD` when
  94the stash was created.  The tree of the second parent records the
  95state of the index when the stash is made, and it is made a child of
  96the `HEAD` commit.  The ancestry graph looks like this:
  97
  98            .----W
  99           /    /
 100     -----H----I
 101
 102where `H` is the `HEAD` commit, `I` is a commit that records the state
 103of the index, and `W` is a commit that records the state of the working
 104tree.
 105
 106
 107EXAMPLES
 108--------
 109
 110Pulling into a dirty tree::
 111
 112When you are in the middle of something, you learn that there are
 113upstream changes that are possibly relevant to what you are
 114doing.  When your local changes do not conflict with the changes in
 115the upstream, a simple `git pull` will let you move forward.
 116+
 117However, there are cases in which your local changes do conflict with
 118the upstream changes, and `git pull` refuses to overwrite your
 119changes.  In such a case, you can stash your changes away,
 120perform a pull, and then unstash, like this:
 121+
 122----------------------------------------------------------------
 123$ git pull
 124...
 125file foobar not up to date, cannot merge.
 126$ git stash
 127$ git pull
 128$ git stash apply
 129----------------------------------------------------------------
 130
 131Interrupted workflow::
 132
 133When you are in the middle of something, your boss comes in and
 134demands that you fix something immediately.  Traditionally, you would
 135make a commit to a temporary branch to store your changes away, and
 136return to your original branch to make the emergency fix, like this:
 137+
 138----------------------------------------------------------------
 139... hack hack hack ...
 140$ git checkout -b my_wip
 141$ git commit -a -m "WIP"
 142$ git checkout master
 143$ edit emergency fix
 144$ git commit -a -m "Fix in a hurry"
 145$ git checkout my_wip
 146$ git reset --soft HEAD^
 147... continue hacking ...
 148----------------------------------------------------------------
 149+
 150You can use `git-stash` to simplify the above, like this:
 151+
 152----------------------------------------------------------------
 153... hack hack hack ...
 154$ git stash
 155$ edit emergency fix
 156$ git commit -a -m "Fix in a hurry"
 157$ git stash apply
 158... continue hacking ...
 159----------------------------------------------------------------
 160
 161SEE ALSO
 162--------
 163linkgit:git-checkout[1],
 164linkgit:git-commit[1],
 165linkgit:git-reflog[1],
 166linkgit:git-reset[1]
 167
 168AUTHOR
 169------
 170Written by Nanako Shiraishi <nanako3@bluebottle.com>
 171
 172GIT
 173---
 174Part of the linkgit:git[7] suite