fix config reading in tests
[git/dscho.git] / Documentation / git-stash.txt
blobcd0dc1bd9d53282d65c52e6b9ded6d40fe087598
1 git-stash(1)
2 ============
4 NAME
5 ----
6 git-stash - Stash the changes in a dirty working directory away
8 SYNOPSIS
9 --------
10 [verse]
11 'git-stash' (list | show [<stash>] | apply [<stash>] | clear)
12 'git-stash' [save [<message>]]
14 DESCRIPTION
15 -----------
17 Use 'git-stash' when you want to record the current state of the
18 working directory and the index, but want to go back to a clean
19 working directory.  The command saves your local modifications away
20 and reverts the working directory to match the `HEAD` commit.
22 The 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`.
25 Calling git-stash without any arguments is equivalent to `git-stash
26 save`.  A stash is by default listed as "WIP on 'branchname' ...", but
27 you can give a more descriptive message on the command line when
28 you create one.
30 The latest stash you created is stored in `$GIT_DIR/refs/stash`; older
31 stashes are found in the reflog of this reference and can be named using
32 the usual reflog syntax (e.g. `stash@\{0}` is the most recently
33 created stash, `stash@\{1}` is the one before it, `stash@\{2.hours.ago}`
34 is also possible).
36 OPTIONS
37 -------
39 save [<message>]::
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.
46 list::
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.
54 ----------------------------------------------------------------
55 stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
56 stash@{1}: On master: 9cc0589... Add git-stash
57 ----------------------------------------------------------------
59 show [<stash>]::
61         Show the changes recorded in the stash as a diff between the
62         stashed state and its original parent. When no `<stash>` is given,
63         shows the latest one. By default, the command shows the diffstat, but
64         it will accept any format known to `git-diff` (e.g., `git-stash show
65         -p stash@\{1}` to view the second most recent stash in patch form).
67 apply [--index] [<stash>]::
69         Restore the changes recorded in the stash on top of the current
70         working tree state.  When no `<stash>` is given, applies the latest
71         one.  The working directory must match the index.
73 This operation can fail with conflicts; you need to resolve them
74 by hand in the working tree.
76 If the `--index` option is used, then tries to reinstate not only the working
77 tree's changes, but also the index's ones. However, this can fail, when you
78 have conflicts (which are stored in the index, where you therefore can no
79 longer apply the changes as they were originally).
81 clear::
82         Remove all the stashed states. Note that those states will then
83         be subject to pruning, and may be difficult or impossible to recover.
86 DISCUSSION
87 ----------
89 A stash is represented as a commit whose tree records the state of the
90 working directory, and its first parent is the commit at `HEAD` when
91 the stash was created.  The tree of the second parent records the
92 state of the index when the stash is made, and it is made a child of
93 the `HEAD` commit.  The ancestry graph looks like this:
95             .----W
96            /    /
97      -----H----I
99 where `H` is the `HEAD` commit, `I` is a commit that records the state
100 of the index, and `W` is a commit that records the state of the working
101 tree.
104 EXAMPLES
105 --------
107 Pulling into a dirty tree::
109 When you are in the middle of something, you learn that there are
110 upstream changes that are possibly relevant to what you are
111 doing.  When your local changes do not conflict with the changes in
112 the upstream, a simple `git pull` will let you move forward.
114 However, there are cases in which your local changes do conflict with
115 the upstream changes, and `git pull` refuses to overwrite your
116 changes.  In such a case, you can stash your changes away,
117 perform a pull, and then unstash, like this:
119 ----------------------------------------------------------------
120 $ git pull
122 file foobar not up to date, cannot merge.
123 $ git stash
124 $ git pull
125 $ git stash apply
126 ----------------------------------------------------------------
128 Interrupted workflow::
130 When you are in the middle of something, your boss comes in and
131 demands that you fix something immediately.  Traditionally, you would
132 make a commit to a temporary branch to store your changes away, and
133 return to your original branch to make the emergency fix, like this:
135 ----------------------------------------------------------------
136 ... hack hack hack ...
137 $ git checkout -b my_wip
138 $ git commit -a -m "WIP"
139 $ git checkout master
140 $ edit emergency fix
141 $ git commit -a -m "Fix in a hurry"
142 $ git checkout my_wip
143 $ git reset --soft HEAD^
144 ... continue hacking ...
145 ----------------------------------------------------------------
147 You can use `git-stash` to simplify the above, like this:
149 ----------------------------------------------------------------
150 ... hack hack hack ...
151 $ git stash
152 $ edit emergency fix
153 $ git commit -a -m "Fix in a hurry"
154 $ git stash apply
155 ... continue hacking ...
156 ----------------------------------------------------------------
158 SEE ALSO
159 --------
160 linkgit:git-checkout[1],
161 linkgit:git-commit[1],
162 linkgit:git-reflog[1],
163 linkgit:git-reset[1]
165 AUTHOR
166 ------
167 Written by Nanako Shiraishi <nanako3@bluebottle.com>
171 Part of the linkgit:git[7] suite