Corrected post formatting

2008-04-23-git-using-the-stash
This commit is contained in:
Ariejan de Vroom 2013-05-10 12:14:57 +02:00
parent 1fff075b4b
commit 15bc5d38a2

View File

@ -9,50 +9,69 @@ tags:
- stash
---
I bet the following has happened to you: you are happily working on a project and are in the middle of something. You are not ready to commit your changes, because you your tests don't pass yet. Then your client calls with a bug report that needs to be fixed <strong>right now</strong>. (You know how clients can be.)
I bet the following has happened to you: you are happily working on a project
and are in the middle of something. You are not ready to commit your changes,
because you your tests don't pass yet. Then your client calls with a bug report
that needs to be fixed **right now**. (You know how clients can
be.)
So, what do you do? Throw away your current changes to make the patch? Checkout a clean copy of your project to make the changes? No! You just stash your changes away, and make the patch! Afterward you grab your changes back and continue work.
So, what do you do? Throw away your current changes to make the patch? Checkout
a clean copy of your project to make the changes? No! You just stash your
changes away, and make the patch! Afterward you grab your changes back and
continue work.
Git features <em>The Stash</em>, which is as much as a good place to store uncommitted changes. When you stash you changes, the will be stored, and your working copy will be reverted to HEAD (the last commit revision) of your code.
Git features _The Stash_, which is as much as a good place to store uncommitted
changes. When you stash you changes, the will be stored, and your working copy
will be reverted to HEAD (the last commit revision) of your code.
When you restore your stash, you changes are reapplied and you continue working on your code.
When you restore your stash, you changes are reapplied and you continue working
on your code.
<strong>Stash your current changes</strong>
**Stash your current changes**
<pre lang="sh">$ git stash save <message for later reference>
$ git stash save <optional message for later reference>
Saved "WIP on master: e71813e..."</pre>
<strong>List current stashes</strong>
**List current stashes**
Yes, you can have more than one!! The stash works like a stack. Every time you save a new stash, it's put on top of the stack.
Yes, you can have more than one!! The stash works like a stack. Every time you
save a new stash, it's put on top of the stack.
<pre lang="sh">$ git stash list
stash@{0}: WIP on master: e71813e..."</pre>
$ git stash list
stash@{0}: WIP on master: e71813e...
Note the stash@{0} part? That's your stash ID, you'll need it to restore it later on. Let's do that right now. The stash ID changes with every stash you make. stash@{0} refers to the last stash you made.
Note the `stash@{0}` part? That's your stash ID, you'll need it to restore it
later on. Let's do that right now. The stash ID changes with every stash you
make. `stash@{0}` refers to the last stash you made.
<strong>Apply a stash</strong>
**Apply a stash**
<pre lang="sh">$ git stash apply stash@{0}</pre>
$ git stash apply stash@{0}
You may notice the stash is still there after you have applied it. You can drop it if you don't need it any more.
You may notice the stash is still there after you have applied it. You can drop
it if you don't need it any more.
<pre lang="sh">$ git stash drop stash@{0}</pre>
$ git stash drop stash@{0}
Or, because the stash acts like a stack, you can pop off the last stash you saved:
Or, because the stash acts like a stack, you can pop off the last stash you
saved:
<pre lang="sh">$ git stash pop</pre>
$ git stash pop
If you want to wipe all your stashes away, run the 'clear' command:
<pre lang="sh">$ git stash clear</pre>
$ git stash clear
It may very well be that you don't use stashes that often. If you just want to quickly stash your changes to restore them later, you can leave out the stash ID.
It may very well be that you don't use stashes that often. If you just want to
quickly stash your changes to restore them later, you can leave out the stash
ID.
<pre lang="sh">$ git stash
$ git stash
...
$ git stash pop</pre>
$ git stash pop
Feel free to experiment with the stash before using it on some really important work.
Feel free to experiment with the stash before using it on some really important
work.
<strong>Please leave a comment if you like this article, and would like to see more Git related stuff here on Ariejan.net.</strong>
**Please leave a comment if you like this article, and would like to see more
Git related stuff here on Ariejan.net.**