Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>According to the <a href="http://git-scm.com/docs/git-stash" rel="noreferrer">git-stash manpage</a>, "A stash is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at <code>HEAD</code> when the stash was created," and <code>git stash show -p</code> gives us "the changes recorded in the stash as a diff between the stashed state and its original parent.</p> <p>To keep your other changes intact, use <code>git stash show -p | patch --reverse</code> as in the following:</p> <pre><code>$ git init Initialized empty Git repository in /tmp/repo/.git/ $ echo Hello, world &gt;messages $ git add messages $ git commit -am 'Initial commit' [master (root-commit)]: created 1ff2478: "Initial commit" 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 messages $ echo Hello again &gt;&gt;messages $ git stash $ git status # On branch master nothing to commit (working directory clean) $ git stash apply # On branch master # Changed but not updated: # (use "git add &lt;file&gt;..." to update what will be committed) # (use "git checkout -- &lt;file&gt;..." to discard changes in working directory) # # modified: messages # no changes added to commit (use "git add" and/or "git commit -a") $ echo Howdy all &gt;&gt;messages $ git diff diff --git a/messages b/messages index a5c1966..eade523 100644 --- a/messages +++ b/messages @@ -1 +1,3 @@ Hello, world +Hello again +Howdy all $ git stash show -p | patch --reverse patching file messages Hunk #1 succeeded at 1 with fuzz 1. $ git diff diff --git a/messages b/messages index a5c1966..364fc91 100644 --- a/messages +++ b/messages @@ -1 +1,2 @@ Hello, world +Howdy all </code></pre> <p><strong>Edit:</strong></p> <p>A light improvement to this is to use <code>git apply</code> in place of patch:</p> <pre><code>git stash show -p | git apply --reverse </code></pre> <p>Alternatively, you can also use <code>git apply -R</code> as a shorthand to <code>git apply --reverse</code>.</p> <p>I've been finding this really handy lately...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload