diff --git a/_layouts/reference.html b/_layouts/reference.html index f1ba9cf..ba90ddb 100755 --- a/_layouts/reference.html +++ b/_layouts/reference.html @@ -51,6 +51,7 @@
In a nutshell,
you run git rm
to remove files from being tracked in Git. It
- will also remove them from your working directory.
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. git stash
is there for you.
+
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. +
+ +
+$ git status -s
+M hello.rb
+$ git stash
+Saved working directory and index state WIP on master: 5857ac1 hello with a flower
+HEAD is now at 5857ac1 hello with a flower
+$ git status
+# On branch master
+nothing to commit (working directory clean)
+
+
+ It's helpful to know what you've got stowed on the stash and this is where
+ git stash list
comes in. Running this command will display a queue
+ of current stash items.
+
+$ git stash list +stash@{0}: WIP on master: 5857ac1 hello with a flower ++ +
The last item added onto the stash will be referenced by
+ stash@{0}
and increment those already there by one.
+
+$ vim hello.rb +$ git commit -am 'it stops raining' +[master ee2d2c6] it stops raining +1 files changed, 1 insertions(+), 1 deletions(-) +$ vim hello.rb +$ git stash +Saved working directory and index state WIP on master: ee2d2c6 it stops raining +HEAD is now at ee2d2c6 it stops raining +$ git stash list +stash@{0}: WIP on master: ee2d2c6 it stops raining +stash@{1}: WIP on master: 5857ac1 hello with a flower ++ +
When you're ready to continue from where you left off, run the
+ git stash apply
command to bring back the saved changes
+ onto the working directory.
+
+$ git stash apply
+# 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)
+#
+# modified: hello.rb
+#
+no changes added to commit (use "git add" and/or "git commit -a")
+
+
+ By default it will reapply the last added stash item to the working
+ directory. This will be the item referenced by stash@{0}
.
+ You can grab another stash item instead if you reference it in the arguments
+ list. For example, git stash apply stash@{1}
will apply the item
+ referenced by stash@{1}
.
+
If you also want to remove the item from the stack at the same time,
+ use git stash pop
instead.
+
When you're done with the stashed item and/or want to remove it from the
+ list, run the git stash drop
command. By default this will
+ remove the last added stash item. You can also remove a specific item if
+ you include it as an argument.
+
In this example, our stash list has at least two items, but we want
+ to get rid of the item added before last, which is referenced by
+ stash@{1}
.
+
+$ git stash drop stash@{1} +Dropped stash@{1} (0b1478540189f30fef9804684673907c65865d8f) ++ +
If you want to remove of all the stored items, just run
+ the git stash clear
command. But only do this if you're
+ sure you're done with the stash.
+
+ In a nutshell, run git stash
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.