Basic ropes on git stash command
Quick overview on what `git stash` is and some of the basic commands to run with it. Going with `git stash pop` as the default means of extracting from the stack instead of `git stash apply`. Former feels like the path of least surprise by taking out what you've just put in. As requested in #36
This commit is contained in:
parent
cfb6480f51
commit
bf91400618
@ -51,6 +51,7 @@
|
|||||||
<li><a href="/basic/#commit">commit</a></li>
|
<li><a href="/basic/#commit">commit</a></li>
|
||||||
<li><a href="/basic/#reset">reset</a></li>
|
<li><a href="/basic/#reset">reset</a></li>
|
||||||
<li><a href="/basic/#rm-mv">rm, mv</a></li>
|
<li><a href="/basic/#rm-mv">rm, mv</a></li>
|
||||||
|
<li><a href="/basic/#stash">stash</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
108
basic/index.html
108
basic/index.html
@ -818,7 +818,113 @@ nothing to commit (working directory clean)
|
|||||||
<p class="nutshell">
|
<p class="nutshell">
|
||||||
<strong>In a nutshell</strong>,
|
<strong>In a nutshell</strong>,
|
||||||
you run <code>git rm</code> to remove files from being tracked in Git. It
|
you run <code>git rm</code> to remove files from being tracked in Git. It
|
||||||
will also remove them from your working directory.</p>
|
will also remove them from your working directory.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2>
|
||||||
|
<span class="docs">
|
||||||
|
<a href="http://git-scm.com/docs/git-stash">docs</a>
|
||||||
|
<a href="http://git-scm.com/book/en/Git-Tools-Stashing">book</a>
|
||||||
|
</span>
|
||||||
|
<a name="stash">git stash</a>
|
||||||
|
<span class="desc">save changes made in the current index and working directory for later</span>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="block">
|
||||||
|
|
||||||
|
<p>You're in the middle of some changes but something comes up that you
|
||||||
|
need to jump over to, like a so-urgent-right-now bugfix, but don't want
|
||||||
|
to commit or lose your current edits. <code>git stash</code> is there for you.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
git stash
|
||||||
|
<small>add current changes to the stack</small>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<p>Stashing takes the current state of the working directory and index,
|
||||||
|
puts it on a stack for later, and gives you back a clean working directory.
|
||||||
|
It will then leave you at the state of the last commit.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>$ git status -s</b>
|
||||||
|
<span class="red">M</span> hello.rb
|
||||||
|
<b>$ git stash</b>
|
||||||
|
Saved working directory and index state WIP on master: 5857ac1 hello with a flower
|
||||||
|
HEAD is now at 5857ac1 hello with a flower
|
||||||
|
<b>$ git status</b>
|
||||||
|
# On branch master
|
||||||
|
nothing to commit (working directory clean)
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
git stash list
|
||||||
|
<small>view stashes currently on the stack</small>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<p>It's helpful to know what you've got stowed on the stash and this is where
|
||||||
|
<code>git stash list</code> comes in. Running this command will display a queue
|
||||||
|
of current stash items.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>$ git stash list</b>
|
||||||
|
stash@{0}: WIP on master: 5857ac1 hello with a flower
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
git stash pop
|
||||||
|
<small>remove item from the list and apply to current working directory</small>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<p>After you've done the changes you were called away for, and you're ready to
|
||||||
|
continue from where you left off, run the <code>git stash pop</code> command
|
||||||
|
to bring back the working directory to that state and remove it from the stash list.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>$ git stash pop</b>
|
||||||
|
# On branch master
|
||||||
|
# Changes not staged for commit:
|
||||||
|
# (use "git add <file>..." to update what will be committed)
|
||||||
|
# (use "git checkout -- <file>..." to discard changes in working directory)
|
||||||
|
#
|
||||||
|
# <span class="red">modified: hello.rb</span>
|
||||||
|
#
|
||||||
|
no changes added to commit (use "git add" and/or "git commit -a")
|
||||||
|
Dropped refs/stash@{0}: (14ddbc6f2c26330e33d08faf15d88f816b6cbd45)
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p>By default it will reapply the last added stash item to the working
|
||||||
|
directory. This will be the item referenced by <code>stash@{0}</code>.
|
||||||
|
You can grab another stash item instead if you reference it in the arguments
|
||||||
|
list. For example, <code>git stash pop stash@{1}</code> will apply the item
|
||||||
|
referenced by <code>stash@{1}</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>If you want to leave the item on the stack, use
|
||||||
|
<code>git stash apply</code> instead.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
git stash clear
|
||||||
|
<small>remove all items from the stash list</small>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<p>When you're done with the stash and/or you want to remove of all the
|
||||||
|
stored items, just run the <code>git stash clear</code> command. But only
|
||||||
|
do this if you're sure you're done with the stash.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="nutshell">
|
||||||
|
<strong>In a nutshell</strong>, run <code>git stash</code> to quickly save
|
||||||
|
some changes that you're not ready to commit or save, but want to come
|
||||||
|
back to while you work on something else.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user