From bf91400618097a5313cb6e0f19c62e29e1e368e8 Mon Sep 17 00:00:00 2001 From: Soon Van Date: Sat, 22 Dec 2012 01:06:34 -0500 Subject: [PATCH] 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 --- _layouts/reference.html | 1 + basic/index.html | 108 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) 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 @@
  • commit
  • reset
  • rm, mv
  • +
  • stash
  • diff --git a/basic/index.html b/basic/index.html index 50b6363..d61568e 100644 --- a/basic/index.html +++ b/basic/index.html @@ -818,7 +818,113 @@ nothing to commit (working directory clean)

    In a nutshell, you run git rm to remove files from being tracked in Git. It - will also remove them from your working directory.

    + will also remove them from your working directory. +

    + + + + +
    +

    + + docs   + book + + git stash + save changes made in the current index and working directory for later +

    + +
    + +

    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. +

    + +

    + git stash + add current changes to the stack +

    + +

    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)
    +
    + +

    + git stash list + view stashes currently on the stack +

    + +

    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
    +
    + +

    + git stash pop + remove item from the list and apply to current working directory +

    + +

    After you've done the changes you were called away for, and you're ready to + continue from where you left off, run the git stash pop command + to bring back the working directory to that state and remove it from the stash list. +

    + +
    +$ git stash pop
    +# 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")
    +Dropped refs/stash@{0}: (14ddbc6f2c26330e33d08faf15d88f816b6cbd45)
    +
    + +

    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 pop stash@{1} will apply the item + referenced by stash@{1}. +

    + +

    If you want to leave the item on the stack, use + git stash apply instead. +

    + +

    + git stash clear + remove all items from the stash list +

    + +

    When you're done with the stash and/or 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.