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