Git diff against a stash











up vote
1044
down vote

favorite
220












How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!










share|improve this question




















  • 8




    possible duplicate of Is it possible to preview stash application in git?
    – quazgar
    Apr 17 '15 at 13:48






  • 1




    Related post here.
    – RBT
    Sep 25 '17 at 6:00















up vote
1044
down vote

favorite
220












How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!










share|improve this question




















  • 8




    possible duplicate of Is it possible to preview stash application in git?
    – quazgar
    Apr 17 '15 at 13:48






  • 1




    Related post here.
    – RBT
    Sep 25 '17 at 6:00













up vote
1044
down vote

favorite
220









up vote
1044
down vote

favorite
220






220





How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!










share|improve this question















How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!







git git-stash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '15 at 16:15









SQB

3,56511740




3,56511740










asked Oct 6 '11 at 16:48









Prospero

8,561133764




8,561133764








  • 8




    possible duplicate of Is it possible to preview stash application in git?
    – quazgar
    Apr 17 '15 at 13:48






  • 1




    Related post here.
    – RBT
    Sep 25 '17 at 6:00














  • 8




    possible duplicate of Is it possible to preview stash application in git?
    – quazgar
    Apr 17 '15 at 13:48






  • 1




    Related post here.
    – RBT
    Sep 25 '17 at 6:00








8




8




possible duplicate of Is it possible to preview stash application in git?
– quazgar
Apr 17 '15 at 13:48




possible duplicate of Is it possible to preview stash application in git?
– quazgar
Apr 17 '15 at 13:48




1




1




Related post here.
– RBT
Sep 25 '17 at 6:00




Related post here.
– RBT
Sep 25 '17 at 6:00












11 Answers
11






active

oldest

votes

















up vote
1443
down vote



accepted










See the most recent stash:



git stash show -p


See an arbitrary stash:



git stash show -p stash@{1}


From the git stash manpages:




By default, the command shows the diffstat, but it will accept any
format known to git diff (e.g., git stash show -p stash@{1} to view
the second most recent stash in patch form).







share|improve this answer



















  • 64




    stash@{0} is the default; you only need an argument if you want to look at previous stashes.
    – Cascabel
    Oct 6 '11 at 17:01






  • 46




    Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
    – Amber
    Oct 6 '11 at 17:16






  • 58




    This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
    – Magne
    Jan 21 '13 at 12:31






  • 10




    @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
    – Magne
    Jan 23 '13 at 10:05






  • 4




    powershell note: git stash show -p "stash@{0}"
    – nexuzzz
    May 14 '15 at 18:14


















up vote
257
down vote













To see the most recent stash:



git stash show -p


To see an arbitrary stash:



git stash show -p stash@{1}


Also, I use git diff to compare the stash with any branch.



You can use:



git diff stash@{0} master


To see all changes compared to branch master.




Or You can use:



git diff --name-only stash@{0} master


To easy find only changed file names.






share|improve this answer



















  • 9




    This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
    – Tom De Leu
    Aug 1 '12 at 14:40








  • 46




    I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
    – Rebekah Waterbury
    Aug 3 '12 at 18:04






  • 6




    this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
    – Andre Holzner
    Oct 19 '12 at 14:22






  • 9




    @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
    – erikprice
    Jan 18 '13 at 19:09








  • 1




    As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
    – David
    Aug 10 '16 at 15:28


















up vote
82
down vote













If the branch that your stashed changes are based on has changed in the meantime, this command may be useful:



git diff stash@{0}^!


This compares the stash against the commit it is based on.






share|improve this answer





















  • so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
    – sbeam
    Mar 17 '14 at 12:12






  • 3




    Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
    – ChrisV
    Jun 15 '14 at 18:13






  • 12




    For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
    – Jonathan Gawrych
    Feb 3 '15 at 16:56










  • "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
    – Naga Kiran
    Oct 20 '15 at 14:05










  • I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
    – user107172
    Aug 23 '17 at 1:49


















up vote
33
down vote













If your working tree is dirty, you can compare it to a stash by first committing the dirty working tree, and then comparing it to the stash. Afterwards, you may undo the commit with the dirty working tree (since you might not want to have that dirty commit in your commit log).



You can also use the following approach to compare two stashes with each other (in which case you just pop one of the stashes at first).





  • Commit your dirty working tree:



    git add .
    git commit -m "Dirty commit"



  • Diff the stash with that commit:



    git diff HEAD stash@{0}



  • Then, afterwards, you may revert the commit, and put it back in the working dir:



    git reset --soft HEAD~1
    git reset .



Now you've diffed the dirty working tree with your stash, and are back to where you were initially.






share|improve this answer























  • Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
    – lagweezle
    Oct 4 '16 at 19:14










  • @lagweezle you can always just diff the stash..
    – Magne
    Oct 7 '16 at 12:22




















up vote
17
down vote













This works for me on git version 1.8.5.2:



git diff stash HEAD





share|improve this answer





















  • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
    – MikeJansen
    Feb 11 '16 at 14:10










  • Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
    – yerlilbilgin
    Feb 12 '16 at 8:37










  • Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
    – yerlilbilgin
    Feb 12 '16 at 8:39










  • @yerlilbilgin See my response on your answer below.
    – MikeJansen
    Feb 23 '16 at 14:51










  • We can ommit HEAD, it's by default, isn't it?
    – Al.G.
    Oct 9 '16 at 12:37


















up vote
15
down vote













@Magne's answer is the only one to (very late) date that answers the most flexible/useful interpretation of the question, but its a fair bit more complicated than necessary. Rather than committing and resetting, just stash your working copy, compare, then unstash.



git stash save "temp"
git diff stash@{0} stash@{1}
git stash pop


That shows you the differences between the top of the stash stack and your working folder by temporarily making your working folder changes become the top of the stash stack (stash@{0}), moving the original top down one (stash@{1}) then comparing using the original top in the 'new set' position so you see the changes that would result from applying it on top of your current work.



"But what if I don't have any current work?" Then you are in the normal boring case. Just use @Amber's answer



git stash show


or @czerasz's answer



git diff stash@{0}


or admit that stashing and unstashing is fast and easy anyway, just unstash the changes and inspect them. If you don't want them at the moment throw them (the current index/working folder changes) away. In full that's



git stash apply
git diff
git reset
git checkout





share|improve this answer



















  • 1




    This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
    – mleonard
    Nov 22 at 12:32


















up vote
9
down vote













If you have tools for diff (like beyond compare)



git difftool stash HEAD





share|improve this answer





















  • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
    – MikeJansen
    Feb 11 '16 at 14:10






  • 1




    If you think this is misleading, please check all the other answers. That is not fair!
    – yerlilbilgin
    Feb 23 '16 at 7:28








  • 1




    You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
    – MikeJansen
    Feb 23 '16 at 14:50






  • 1




    This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
    – Sridhar-Sarnobat
    Jan 5 at 22:45




















up vote
2
down vote













FWIW
This may be a bit redundant to all the other answers and is very similar to the accepted answer which is spot on; but maybe it will help someone out.



git stash show --help will give you all you should need; including stash show info.




show [<stash>]




Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form). You can use stash.showStat and/or stash.showPatch config variables to change the default behavior.








share|improve this answer




























    up vote
    1
    down vote













    One way to do this without moving anything is to take advantage of the fact that patch can read git diff's (unified diffs basically)



    git stash show -p | patch -p1 --verbose --dry-run


    This will show you a step-by-step preview of what patch would ordinarily do. The added benefit to this is that patch won't prevent itself from writing the patch to the working tree either, if for some reason you just really need git to shut up about commiting-before-modifying, go ahead and remove --dry-run and follow the verbose instructions.






    share|improve this answer




























      up vote
      0
      down vote













      Combining what I learned in this thread and in this one, when I want to see "what is inside the stash", I first run:



      git stash show stash@{0}


      That will show what files were modified. Then, to get a nice visual diff in a difftool, I do:



      git difftool --dir-diff stash@{0} stash@{0}^


      This will display all the differences at once of the given stash against its parent.



      You can configure the diff tool in ~/.gitconfig, e.g. with Meld:



      ...
      [diff]
      tool = meld





      share|improve this answer






























        up vote
        0
        down vote













        She the list of stash



        git stash list 
        stash@{0}: WIP on feature/blabla: 830335224fa Name Commit
        stash@{1}: WIP on feature/blabla2: 830335224fa Name Commit 2


        So get the stash number and do:



        You can do:



         git stash show -p stash@{1}


        But if you want a diff (this is different to show the stash, that's why I write this answer. Diff consider the current code in your branch and show just show what you will apply)



        You can use:



        git diff stash@{0}


        or



        git diff stash@{0} <branch name>


        Another interesting thing to do is:



        git stash apply
        git stash apply stash@{10}


        This applies the stash without removing it from the list, you can git checkout . to remove those change or if you are happy git stash drop stash@{10} to remove a stash from the list.



        From here I never recommend to use git stash pop and use a combination of git stash apply and git stash drop If you apply a stash in the wrong branch... well sometimes is difficult to recover your code.






        share|improve this answer





















          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7677736%2fgit-diff-against-a-stash%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          11 Answers
          11






          active

          oldest

          votes








          11 Answers
          11






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1443
          down vote



          accepted










          See the most recent stash:



          git stash show -p


          See an arbitrary stash:



          git stash show -p stash@{1}


          From the git stash manpages:




          By default, the command shows the diffstat, but it will accept any
          format known to git diff (e.g., git stash show -p stash@{1} to view
          the second most recent stash in patch form).







          share|improve this answer



















          • 64




            stash@{0} is the default; you only need an argument if you want to look at previous stashes.
            – Cascabel
            Oct 6 '11 at 17:01






          • 46




            Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
            – Amber
            Oct 6 '11 at 17:16






          • 58




            This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
            – Magne
            Jan 21 '13 at 12:31






          • 10




            @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
            – Magne
            Jan 23 '13 at 10:05






          • 4




            powershell note: git stash show -p "stash@{0}"
            – nexuzzz
            May 14 '15 at 18:14















          up vote
          1443
          down vote



          accepted










          See the most recent stash:



          git stash show -p


          See an arbitrary stash:



          git stash show -p stash@{1}


          From the git stash manpages:




          By default, the command shows the diffstat, but it will accept any
          format known to git diff (e.g., git stash show -p stash@{1} to view
          the second most recent stash in patch form).







          share|improve this answer



















          • 64




            stash@{0} is the default; you only need an argument if you want to look at previous stashes.
            – Cascabel
            Oct 6 '11 at 17:01






          • 46




            Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
            – Amber
            Oct 6 '11 at 17:16






          • 58




            This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
            – Magne
            Jan 21 '13 at 12:31






          • 10




            @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
            – Magne
            Jan 23 '13 at 10:05






          • 4




            powershell note: git stash show -p "stash@{0}"
            – nexuzzz
            May 14 '15 at 18:14













          up vote
          1443
          down vote



          accepted







          up vote
          1443
          down vote



          accepted






          See the most recent stash:



          git stash show -p


          See an arbitrary stash:



          git stash show -p stash@{1}


          From the git stash manpages:




          By default, the command shows the diffstat, but it will accept any
          format known to git diff (e.g., git stash show -p stash@{1} to view
          the second most recent stash in patch form).







          share|improve this answer














          See the most recent stash:



          git stash show -p


          See an arbitrary stash:



          git stash show -p stash@{1}


          From the git stash manpages:




          By default, the command shows the diffstat, but it will accept any
          format known to git diff (e.g., git stash show -p stash@{1} to view
          the second most recent stash in patch form).








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 18 '17 at 9:28









          thedayturns

          3,81312033




          3,81312033










          answered Oct 6 '11 at 16:50









          Amber

          346k60520483




          346k60520483








          • 64




            stash@{0} is the default; you only need an argument if you want to look at previous stashes.
            – Cascabel
            Oct 6 '11 at 17:01






          • 46




            Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
            – Amber
            Oct 6 '11 at 17:16






          • 58




            This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
            – Magne
            Jan 21 '13 at 12:31






          • 10




            @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
            – Magne
            Jan 23 '13 at 10:05






          • 4




            powershell note: git stash show -p "stash@{0}"
            – nexuzzz
            May 14 '15 at 18:14














          • 64




            stash@{0} is the default; you only need an argument if you want to look at previous stashes.
            – Cascabel
            Oct 6 '11 at 17:01






          • 46




            Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
            – Amber
            Oct 6 '11 at 17:16






          • 58




            This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
            – Magne
            Jan 21 '13 at 12:31






          • 10




            @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
            – Magne
            Jan 23 '13 at 10:05






          • 4




            powershell note: git stash show -p "stash@{0}"
            – nexuzzz
            May 14 '15 at 18:14








          64




          64




          stash@{0} is the default; you only need an argument if you want to look at previous stashes.
          – Cascabel
          Oct 6 '11 at 17:01




          stash@{0} is the default; you only need an argument if you want to look at previous stashes.
          – Cascabel
          Oct 6 '11 at 17:01




          46




          46




          Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
          – Amber
          Oct 6 '11 at 17:16




          Right. I merely supplied it so that it was clear how to look at other stashes besides {0}.
          – Amber
          Oct 6 '11 at 17:16




          58




          58




          This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
          – Magne
          Jan 21 '13 at 12:31




          This won't show the diff between the stash and the current working dir, but between the stash and it's original parent. Right? From the manpage: "Show the changes recorded in the stash as a diff between the stashed state and its original parent."
          – Magne
          Jan 21 '13 at 12:31




          10




          10




          @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
          – Magne
          Jan 23 '13 at 10:05




          @Amber - True, although if your current working tree is dirty, it matters, and makes it a bit more complicated. I came at it from that angle, and found an procedure I shared in my answer below.
          – Magne
          Jan 23 '13 at 10:05




          4




          4




          powershell note: git stash show -p "stash@{0}"
          – nexuzzz
          May 14 '15 at 18:14




          powershell note: git stash show -p "stash@{0}"
          – nexuzzz
          May 14 '15 at 18:14












          up vote
          257
          down vote













          To see the most recent stash:



          git stash show -p


          To see an arbitrary stash:



          git stash show -p stash@{1}


          Also, I use git diff to compare the stash with any branch.



          You can use:



          git diff stash@{0} master


          To see all changes compared to branch master.




          Or You can use:



          git diff --name-only stash@{0} master


          To easy find only changed file names.






          share|improve this answer



















          • 9




            This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
            – Tom De Leu
            Aug 1 '12 at 14:40








          • 46




            I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
            – Rebekah Waterbury
            Aug 3 '12 at 18:04






          • 6




            this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
            – Andre Holzner
            Oct 19 '12 at 14:22






          • 9




            @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
            – erikprice
            Jan 18 '13 at 19:09








          • 1




            As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
            – David
            Aug 10 '16 at 15:28















          up vote
          257
          down vote













          To see the most recent stash:



          git stash show -p


          To see an arbitrary stash:



          git stash show -p stash@{1}


          Also, I use git diff to compare the stash with any branch.



          You can use:



          git diff stash@{0} master


          To see all changes compared to branch master.




          Or You can use:



          git diff --name-only stash@{0} master


          To easy find only changed file names.






          share|improve this answer



















          • 9




            This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
            – Tom De Leu
            Aug 1 '12 at 14:40








          • 46




            I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
            – Rebekah Waterbury
            Aug 3 '12 at 18:04






          • 6




            this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
            – Andre Holzner
            Oct 19 '12 at 14:22






          • 9




            @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
            – erikprice
            Jan 18 '13 at 19:09








          • 1




            As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
            – David
            Aug 10 '16 at 15:28













          up vote
          257
          down vote










          up vote
          257
          down vote









          To see the most recent stash:



          git stash show -p


          To see an arbitrary stash:



          git stash show -p stash@{1}


          Also, I use git diff to compare the stash with any branch.



          You can use:



          git diff stash@{0} master


          To see all changes compared to branch master.




          Or You can use:



          git diff --name-only stash@{0} master


          To easy find only changed file names.






          share|improve this answer














          To see the most recent stash:



          git stash show -p


          To see an arbitrary stash:



          git stash show -p stash@{1}


          Also, I use git diff to compare the stash with any branch.



          You can use:



          git diff stash@{0} master


          To see all changes compared to branch master.




          Or You can use:



          git diff --name-only stash@{0} master


          To easy find only changed file names.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 2 '17 at 10:39









          Community

          11




          11










          answered Jul 26 '12 at 14:33









          czerasz

          8,61473755




          8,61473755








          • 9




            This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
            – Tom De Leu
            Aug 1 '12 at 14:40








          • 46




            I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
            – Rebekah Waterbury
            Aug 3 '12 at 18:04






          • 6




            this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
            – Andre Holzner
            Oct 19 '12 at 14:22






          • 9




            @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
            – erikprice
            Jan 18 '13 at 19:09








          • 1




            As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
            – David
            Aug 10 '16 at 15:28














          • 9




            This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
            – Tom De Leu
            Aug 1 '12 at 14:40








          • 46




            I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
            – Rebekah Waterbury
            Aug 3 '12 at 18:04






          • 6




            this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
            – Andre Holzner
            Oct 19 '12 at 14:22






          • 9




            @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
            – erikprice
            Jan 18 '13 at 19:09








          • 1




            As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
            – David
            Aug 10 '16 at 15:28








          9




          9




          This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
          – Tom De Leu
          Aug 1 '12 at 14:40






          This does not answer the specific question. If you created the stash from master (to save work for later), then do some commits for other work on master, then do git diff stash@{0} master, you get a diff of your stash against the current master (which includes the work done on master after the stash was made), not the files/lines that the stash would change, which is what the question is about.
          – Tom De Leu
          Aug 1 '12 at 14:40






          46




          46




          I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
          – Rebekah Waterbury
          Aug 3 '12 at 18:04




          I'm glad you answered the question even if it wasn't an answer to the exact question. It gave more information, and I think it's great to know how to get a diff between a branch and whatever other branch you wan to compare it to. I also liked learning the --name-only flag :)
          – Rebekah Waterbury
          Aug 3 '12 at 18:04




          6




          6




          this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
          – Andre Holzner
          Oct 19 '12 at 14:22




          this also allows looking at the differences using a custom diff viewer, e.g. git difftool --tool=... stash@{0} HEAD
          – Andre Holzner
          Oct 19 '12 at 14:22




          9




          9




          @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
          – erikprice
          Jan 18 '13 at 19:09






          @TomDeLeu Good observation and an important point. To compare a stash item with its parent, this seems to work: git diff stash@{0}^ stash@{0}
          – erikprice
          Jan 18 '13 at 19:09






          1




          1




          As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
          – David
          Aug 10 '16 at 15:28




          As well, you can add the filename git diff stash@{0} master -- filename to get the changes to a specific file.
          – David
          Aug 10 '16 at 15:28










          up vote
          82
          down vote













          If the branch that your stashed changes are based on has changed in the meantime, this command may be useful:



          git diff stash@{0}^!


          This compares the stash against the commit it is based on.






          share|improve this answer





















          • so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
            – sbeam
            Mar 17 '14 at 12:12






          • 3




            Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
            – ChrisV
            Jun 15 '14 at 18:13






          • 12




            For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
            – Jonathan Gawrych
            Feb 3 '15 at 16:56










          • "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
            – Naga Kiran
            Oct 20 '15 at 14:05










          • I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
            – user107172
            Aug 23 '17 at 1:49















          up vote
          82
          down vote













          If the branch that your stashed changes are based on has changed in the meantime, this command may be useful:



          git diff stash@{0}^!


          This compares the stash against the commit it is based on.






          share|improve this answer





















          • so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
            – sbeam
            Mar 17 '14 at 12:12






          • 3




            Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
            – ChrisV
            Jun 15 '14 at 18:13






          • 12




            For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
            – Jonathan Gawrych
            Feb 3 '15 at 16:56










          • "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
            – Naga Kiran
            Oct 20 '15 at 14:05










          • I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
            – user107172
            Aug 23 '17 at 1:49













          up vote
          82
          down vote










          up vote
          82
          down vote









          If the branch that your stashed changes are based on has changed in the meantime, this command may be useful:



          git diff stash@{0}^!


          This compares the stash against the commit it is based on.






          share|improve this answer












          If the branch that your stashed changes are based on has changed in the meantime, this command may be useful:



          git diff stash@{0}^!


          This compares the stash against the commit it is based on.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 '13 at 13:23









          t.heintz

          1,2861018




          1,2861018












          • so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
            – sbeam
            Mar 17 '14 at 12:12






          • 3




            Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
            – ChrisV
            Jun 15 '14 at 18:13






          • 12




            For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
            – Jonathan Gawrych
            Feb 3 '15 at 16:56










          • "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
            – Naga Kiran
            Oct 20 '15 at 14:05










          • I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
            – user107172
            Aug 23 '17 at 1:49


















          • so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
            – sbeam
            Mar 17 '14 at 12:12






          • 3




            Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
            – ChrisV
            Jun 15 '14 at 18:13






          • 12




            For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
            – Jonathan Gawrych
            Feb 3 '15 at 16:56










          • "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
            – Naga Kiran
            Oct 20 '15 at 14:05










          • I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
            – user107172
            Aug 23 '17 at 1:49
















          so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
          – sbeam
          Mar 17 '14 at 12:12




          so good I added an alias to ~/.gitconfig : laststash = diff stash@{0}^!
          – sbeam
          Mar 17 '14 at 12:12




          3




          3




          Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
          – ChrisV
          Jun 15 '14 at 18:13




          Perfect pair: git difftool stash^! for diff of last stash against commit it was based on, git difftool stash HEAD for diff of last stash against current commit (stash@{n} for earlier stashes)
          – ChrisV
          Jun 15 '14 at 18:13




          12




          12




          For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
          – Jonathan Gawrych
          Feb 3 '15 at 16:56




          For those who were like me and have never seen the ^! before: commit^! is a range specifier which means: this commit, but none of its parents.
          – Jonathan Gawrych
          Feb 3 '15 at 16:56












          "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
          – Naga Kiran
          Oct 20 '15 at 14:05




          "git diff stash@{0}^!" boils down to "git diff stash@{0} ^stash@{0}~1 ^stash@{0}~2 ......." but as git diff takes only 2 commits, it shows the diff between stash@{0} and ^stash@{0}~1 and looks the ^ at the beginning of 2nd commit doesn't make any different and git ignores it.
          – Naga Kiran
          Oct 20 '15 at 14:05












          I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
          – user107172
          Aug 23 '17 at 1:49




          I prefer this version to be able to use my preferred diff tool (Beyond Compare of course!). This also shows the change in this stash which I believe is the original question, as opposed to an alternative mentioned in the above comments "git diff stash@{X}^ stash@{X}" which shows more than just the stashed diff.
          – user107172
          Aug 23 '17 at 1:49










          up vote
          33
          down vote













          If your working tree is dirty, you can compare it to a stash by first committing the dirty working tree, and then comparing it to the stash. Afterwards, you may undo the commit with the dirty working tree (since you might not want to have that dirty commit in your commit log).



          You can also use the following approach to compare two stashes with each other (in which case you just pop one of the stashes at first).





          • Commit your dirty working tree:



            git add .
            git commit -m "Dirty commit"



          • Diff the stash with that commit:



            git diff HEAD stash@{0}



          • Then, afterwards, you may revert the commit, and put it back in the working dir:



            git reset --soft HEAD~1
            git reset .



          Now you've diffed the dirty working tree with your stash, and are back to where you were initially.






          share|improve this answer























          • Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
            – lagweezle
            Oct 4 '16 at 19:14










          • @lagweezle you can always just diff the stash..
            – Magne
            Oct 7 '16 at 12:22

















          up vote
          33
          down vote













          If your working tree is dirty, you can compare it to a stash by first committing the dirty working tree, and then comparing it to the stash. Afterwards, you may undo the commit with the dirty working tree (since you might not want to have that dirty commit in your commit log).



          You can also use the following approach to compare two stashes with each other (in which case you just pop one of the stashes at first).





          • Commit your dirty working tree:



            git add .
            git commit -m "Dirty commit"



          • Diff the stash with that commit:



            git diff HEAD stash@{0}



          • Then, afterwards, you may revert the commit, and put it back in the working dir:



            git reset --soft HEAD~1
            git reset .



          Now you've diffed the dirty working tree with your stash, and are back to where you were initially.






          share|improve this answer























          • Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
            – lagweezle
            Oct 4 '16 at 19:14










          • @lagweezle you can always just diff the stash..
            – Magne
            Oct 7 '16 at 12:22















          up vote
          33
          down vote










          up vote
          33
          down vote









          If your working tree is dirty, you can compare it to a stash by first committing the dirty working tree, and then comparing it to the stash. Afterwards, you may undo the commit with the dirty working tree (since you might not want to have that dirty commit in your commit log).



          You can also use the following approach to compare two stashes with each other (in which case you just pop one of the stashes at first).





          • Commit your dirty working tree:



            git add .
            git commit -m "Dirty commit"



          • Diff the stash with that commit:



            git diff HEAD stash@{0}



          • Then, afterwards, you may revert the commit, and put it back in the working dir:



            git reset --soft HEAD~1
            git reset .



          Now you've diffed the dirty working tree with your stash, and are back to where you were initially.






          share|improve this answer














          If your working tree is dirty, you can compare it to a stash by first committing the dirty working tree, and then comparing it to the stash. Afterwards, you may undo the commit with the dirty working tree (since you might not want to have that dirty commit in your commit log).



          You can also use the following approach to compare two stashes with each other (in which case you just pop one of the stashes at first).





          • Commit your dirty working tree:



            git add .
            git commit -m "Dirty commit"



          • Diff the stash with that commit:



            git diff HEAD stash@{0}



          • Then, afterwards, you may revert the commit, and put it back in the working dir:



            git reset --soft HEAD~1
            git reset .



          Now you've diffed the dirty working tree with your stash, and are back to where you were initially.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 26 '16 at 23:35









          Max Wallace

          2,0651631




          2,0651631










          answered Jan 21 '13 at 13:33









          Magne

          10.6k64558




          10.6k64558












          • Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
            – lagweezle
            Oct 4 '16 at 19:14










          • @lagweezle you can always just diff the stash..
            – Magne
            Oct 7 '16 at 12:22




















          • Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
            – lagweezle
            Oct 4 '16 at 19:14










          • @lagweezle you can always just diff the stash..
            – Magne
            Oct 7 '16 at 12:22


















          Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
          – lagweezle
          Oct 4 '16 at 19:14




          Is there a way to do this but to only see a diff of the files that would be changed by what is in the stash?
          – lagweezle
          Oct 4 '16 at 19:14












          @lagweezle you can always just diff the stash..
          – Magne
          Oct 7 '16 at 12:22






          @lagweezle you can always just diff the stash..
          – Magne
          Oct 7 '16 at 12:22












          up vote
          17
          down vote













          This works for me on git version 1.8.5.2:



          git diff stash HEAD





          share|improve this answer





















          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10










          • Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
            – yerlilbilgin
            Feb 12 '16 at 8:37










          • Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
            – yerlilbilgin
            Feb 12 '16 at 8:39










          • @yerlilbilgin See my response on your answer below.
            – MikeJansen
            Feb 23 '16 at 14:51










          • We can ommit HEAD, it's by default, isn't it?
            – Al.G.
            Oct 9 '16 at 12:37















          up vote
          17
          down vote













          This works for me on git version 1.8.5.2:



          git diff stash HEAD





          share|improve this answer





















          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10










          • Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
            – yerlilbilgin
            Feb 12 '16 at 8:37










          • Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
            – yerlilbilgin
            Feb 12 '16 at 8:39










          • @yerlilbilgin See my response on your answer below.
            – MikeJansen
            Feb 23 '16 at 14:51










          • We can ommit HEAD, it's by default, isn't it?
            – Al.G.
            Oct 9 '16 at 12:37













          up vote
          17
          down vote










          up vote
          17
          down vote









          This works for me on git version 1.8.5.2:



          git diff stash HEAD





          share|improve this answer












          This works for me on git version 1.8.5.2:



          git diff stash HEAD






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 22 '14 at 23:36









          Rimian

          19.9k99198




          19.9k99198












          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10










          • Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
            – yerlilbilgin
            Feb 12 '16 at 8:37










          • Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
            – yerlilbilgin
            Feb 12 '16 at 8:39










          • @yerlilbilgin See my response on your answer below.
            – MikeJansen
            Feb 23 '16 at 14:51










          • We can ommit HEAD, it's by default, isn't it?
            – Al.G.
            Oct 9 '16 at 12:37


















          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10










          • Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
            – yerlilbilgin
            Feb 12 '16 at 8:37










          • Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
            – yerlilbilgin
            Feb 12 '16 at 8:39










          • @yerlilbilgin See my response on your answer below.
            – MikeJansen
            Feb 23 '16 at 14:51










          • We can ommit HEAD, it's by default, isn't it?
            – Al.G.
            Oct 9 '16 at 12:37
















          Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
          – MikeJansen
          Feb 11 '16 at 14:10




          Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
          – MikeJansen
          Feb 11 '16 at 14:10












          Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
          – yerlilbilgin
          Feb 12 '16 at 8:37




          Please read on the question more "I would like to know what changes will be made before applying them!". I am providing a fast answer to this.
          – yerlilbilgin
          Feb 12 '16 at 8:37












          Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
          – yerlilbilgin
          Feb 12 '16 at 8:39




          Also you can see all the other answers are somehow about diff'ing the current head (or working set) against the stash. Why is only my answer misleading? That is not fair.
          – yerlilbilgin
          Feb 12 '16 at 8:39












          @yerlilbilgin See my response on your answer below.
          – MikeJansen
          Feb 23 '16 at 14:51




          @yerlilbilgin See my response on your answer below.
          – MikeJansen
          Feb 23 '16 at 14:51












          We can ommit HEAD, it's by default, isn't it?
          – Al.G.
          Oct 9 '16 at 12:37




          We can ommit HEAD, it's by default, isn't it?
          – Al.G.
          Oct 9 '16 at 12:37










          up vote
          15
          down vote













          @Magne's answer is the only one to (very late) date that answers the most flexible/useful interpretation of the question, but its a fair bit more complicated than necessary. Rather than committing and resetting, just stash your working copy, compare, then unstash.



          git stash save "temp"
          git diff stash@{0} stash@{1}
          git stash pop


          That shows you the differences between the top of the stash stack and your working folder by temporarily making your working folder changes become the top of the stash stack (stash@{0}), moving the original top down one (stash@{1}) then comparing using the original top in the 'new set' position so you see the changes that would result from applying it on top of your current work.



          "But what if I don't have any current work?" Then you are in the normal boring case. Just use @Amber's answer



          git stash show


          or @czerasz's answer



          git diff stash@{0}


          or admit that stashing and unstashing is fast and easy anyway, just unstash the changes and inspect them. If you don't want them at the moment throw them (the current index/working folder changes) away. In full that's



          git stash apply
          git diff
          git reset
          git checkout





          share|improve this answer



















          • 1




            This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
            – mleonard
            Nov 22 at 12:32















          up vote
          15
          down vote













          @Magne's answer is the only one to (very late) date that answers the most flexible/useful interpretation of the question, but its a fair bit more complicated than necessary. Rather than committing and resetting, just stash your working copy, compare, then unstash.



          git stash save "temp"
          git diff stash@{0} stash@{1}
          git stash pop


          That shows you the differences between the top of the stash stack and your working folder by temporarily making your working folder changes become the top of the stash stack (stash@{0}), moving the original top down one (stash@{1}) then comparing using the original top in the 'new set' position so you see the changes that would result from applying it on top of your current work.



          "But what if I don't have any current work?" Then you are in the normal boring case. Just use @Amber's answer



          git stash show


          or @czerasz's answer



          git diff stash@{0}


          or admit that stashing and unstashing is fast and easy anyway, just unstash the changes and inspect them. If you don't want them at the moment throw them (the current index/working folder changes) away. In full that's



          git stash apply
          git diff
          git reset
          git checkout





          share|improve this answer



















          • 1




            This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
            – mleonard
            Nov 22 at 12:32













          up vote
          15
          down vote










          up vote
          15
          down vote









          @Magne's answer is the only one to (very late) date that answers the most flexible/useful interpretation of the question, but its a fair bit more complicated than necessary. Rather than committing and resetting, just stash your working copy, compare, then unstash.



          git stash save "temp"
          git diff stash@{0} stash@{1}
          git stash pop


          That shows you the differences between the top of the stash stack and your working folder by temporarily making your working folder changes become the top of the stash stack (stash@{0}), moving the original top down one (stash@{1}) then comparing using the original top in the 'new set' position so you see the changes that would result from applying it on top of your current work.



          "But what if I don't have any current work?" Then you are in the normal boring case. Just use @Amber's answer



          git stash show


          or @czerasz's answer



          git diff stash@{0}


          or admit that stashing and unstashing is fast and easy anyway, just unstash the changes and inspect them. If you don't want them at the moment throw them (the current index/working folder changes) away. In full that's



          git stash apply
          git diff
          git reset
          git checkout





          share|improve this answer














          @Magne's answer is the only one to (very late) date that answers the most flexible/useful interpretation of the question, but its a fair bit more complicated than necessary. Rather than committing and resetting, just stash your working copy, compare, then unstash.



          git stash save "temp"
          git diff stash@{0} stash@{1}
          git stash pop


          That shows you the differences between the top of the stash stack and your working folder by temporarily making your working folder changes become the top of the stash stack (stash@{0}), moving the original top down one (stash@{1}) then comparing using the original top in the 'new set' position so you see the changes that would result from applying it on top of your current work.



          "But what if I don't have any current work?" Then you are in the normal boring case. Just use @Amber's answer



          git stash show


          or @czerasz's answer



          git diff stash@{0}


          or admit that stashing and unstashing is fast and easy anyway, just unstash the changes and inspect them. If you don't want them at the moment throw them (the current index/working folder changes) away. In full that's



          git stash apply
          git diff
          git reset
          git checkout






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 at 13:50









          mleonard

          37329




          37329










          answered Jun 28 '16 at 16:13









          SensorSmith

          537617




          537617








          • 1




            This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
            – mleonard
            Nov 22 at 12:32














          • 1




            This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
            – mleonard
            Nov 22 at 12:32








          1




          1




          This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
          – mleonard
          Nov 22 at 12:32




          This simple approach (stash and then compare to another stash) is safe and easy to understand. For some use cases you may wish to also stash untracked files with git stash save -u
          – mleonard
          Nov 22 at 12:32










          up vote
          9
          down vote













          If you have tools for diff (like beyond compare)



          git difftool stash HEAD





          share|improve this answer





















          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10






          • 1




            If you think this is misleading, please check all the other answers. That is not fair!
            – yerlilbilgin
            Feb 23 '16 at 7:28








          • 1




            You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
            – MikeJansen
            Feb 23 '16 at 14:50






          • 1




            This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
            – Sridhar-Sarnobat
            Jan 5 at 22:45

















          up vote
          9
          down vote













          If you have tools for diff (like beyond compare)



          git difftool stash HEAD





          share|improve this answer





















          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10






          • 1




            If you think this is misleading, please check all the other answers. That is not fair!
            – yerlilbilgin
            Feb 23 '16 at 7:28








          • 1




            You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
            – MikeJansen
            Feb 23 '16 at 14:50






          • 1




            This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
            – Sridhar-Sarnobat
            Jan 5 at 22:45















          up vote
          9
          down vote










          up vote
          9
          down vote









          If you have tools for diff (like beyond compare)



          git difftool stash HEAD





          share|improve this answer












          If you have tools for diff (like beyond compare)



          git difftool stash HEAD






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 9 '15 at 8:08









          yerlilbilgin

          1,32011315




          1,32011315












          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10






          • 1




            If you think this is misleading, please check all the other answers. That is not fair!
            – yerlilbilgin
            Feb 23 '16 at 7:28








          • 1




            You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
            – MikeJansen
            Feb 23 '16 at 14:50






          • 1




            This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
            – Sridhar-Sarnobat
            Jan 5 at 22:45




















          • Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
            – MikeJansen
            Feb 11 '16 at 14:10






          • 1




            If you think this is misleading, please check all the other answers. That is not fair!
            – yerlilbilgin
            Feb 23 '16 at 7:28








          • 1




            You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
            – MikeJansen
            Feb 23 '16 at 14:50






          • 1




            This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
            – Sridhar-Sarnobat
            Jan 5 at 22:45


















          Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
          – MikeJansen
          Feb 11 '16 at 14:10




          Misleading! The question is: How can I see the changes un-stashing will make to the current working tree? This shows the diff between the stash and the HEAD which may be VERY different than what will be applied with git stash apply.
          – MikeJansen
          Feb 11 '16 at 14:10




          1




          1




          If you think this is misleading, please check all the other answers. That is not fair!
          – yerlilbilgin
          Feb 23 '16 at 7:28






          If you think this is misleading, please check all the other answers. That is not fair!
          – yerlilbilgin
          Feb 23 '16 at 7:28






          1




          1




          You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
          – MikeJansen
          Feb 23 '16 at 14:50




          You'll note that I copied that same comment to the other answer which was just as misleading (pretty much the same answer). Other answers that already had a similar comment I left alone. If you understand how git stash works, then you will realize that diff'ing the stash against HEAD is not what gets applied (which is what the OP asks). The actual "stash" is the diff between the stash commit and what was before it. This patch is then applied to the HEAD. So if you want to know what the OP asked, you must show the diff between the stash and the commit before it, which the correct answers do.
          – MikeJansen
          Feb 23 '16 at 14:50




          1




          1




          This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
          – Sridhar-Sarnobat
          Jan 5 at 22:45






          This answers the question more directly than any of the other (needlessly) long answers, and does exactly what the OP asked, short of removing HEAD. I could modify @yerlilbilgin's answer to remove HEAD but I think anyone who uses git can figure that part out and me lengthening the answer would make it less readable. No blame on @yerlibilgin.
          – Sridhar-Sarnobat
          Jan 5 at 22:45












          up vote
          2
          down vote













          FWIW
          This may be a bit redundant to all the other answers and is very similar to the accepted answer which is spot on; but maybe it will help someone out.



          git stash show --help will give you all you should need; including stash show info.




          show [<stash>]




          Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form). You can use stash.showStat and/or stash.showPatch config variables to change the default behavior.








          share|improve this answer

























            up vote
            2
            down vote













            FWIW
            This may be a bit redundant to all the other answers and is very similar to the accepted answer which is spot on; but maybe it will help someone out.



            git stash show --help will give you all you should need; including stash show info.




            show [<stash>]




            Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form). You can use stash.showStat and/or stash.showPatch config variables to change the default behavior.








            share|improve this answer























              up vote
              2
              down vote










              up vote
              2
              down vote









              FWIW
              This may be a bit redundant to all the other answers and is very similar to the accepted answer which is spot on; but maybe it will help someone out.



              git stash show --help will give you all you should need; including stash show info.




              show [<stash>]




              Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form). You can use stash.showStat and/or stash.showPatch config variables to change the default behavior.








              share|improve this answer












              FWIW
              This may be a bit redundant to all the other answers and is very similar to the accepted answer which is spot on; but maybe it will help someone out.



              git stash show --help will give you all you should need; including stash show info.




              show [<stash>]




              Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form). You can use stash.showStat and/or stash.showPatch config variables to change the default behavior.









              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 18 '16 at 16:40









              Anovative

              6841118




              6841118






















                  up vote
                  1
                  down vote













                  One way to do this without moving anything is to take advantage of the fact that patch can read git diff's (unified diffs basically)



                  git stash show -p | patch -p1 --verbose --dry-run


                  This will show you a step-by-step preview of what patch would ordinarily do. The added benefit to this is that patch won't prevent itself from writing the patch to the working tree either, if for some reason you just really need git to shut up about commiting-before-modifying, go ahead and remove --dry-run and follow the verbose instructions.






                  share|improve this answer

























                    up vote
                    1
                    down vote













                    One way to do this without moving anything is to take advantage of the fact that patch can read git diff's (unified diffs basically)



                    git stash show -p | patch -p1 --verbose --dry-run


                    This will show you a step-by-step preview of what patch would ordinarily do. The added benefit to this is that patch won't prevent itself from writing the patch to the working tree either, if for some reason you just really need git to shut up about commiting-before-modifying, go ahead and remove --dry-run and follow the verbose instructions.






                    share|improve this answer























                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      One way to do this without moving anything is to take advantage of the fact that patch can read git diff's (unified diffs basically)



                      git stash show -p | patch -p1 --verbose --dry-run


                      This will show you a step-by-step preview of what patch would ordinarily do. The added benefit to this is that patch won't prevent itself from writing the patch to the working tree either, if for some reason you just really need git to shut up about commiting-before-modifying, go ahead and remove --dry-run and follow the verbose instructions.






                      share|improve this answer












                      One way to do this without moving anything is to take advantage of the fact that patch can read git diff's (unified diffs basically)



                      git stash show -p | patch -p1 --verbose --dry-run


                      This will show you a step-by-step preview of what patch would ordinarily do. The added benefit to this is that patch won't prevent itself from writing the patch to the working tree either, if for some reason you just really need git to shut up about commiting-before-modifying, go ahead and remove --dry-run and follow the verbose instructions.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 7 at 23:44









                      xenithorb

                      1113




                      1113






















                          up vote
                          0
                          down vote













                          Combining what I learned in this thread and in this one, when I want to see "what is inside the stash", I first run:



                          git stash show stash@{0}


                          That will show what files were modified. Then, to get a nice visual diff in a difftool, I do:



                          git difftool --dir-diff stash@{0} stash@{0}^


                          This will display all the differences at once of the given stash against its parent.



                          You can configure the diff tool in ~/.gitconfig, e.g. with Meld:



                          ...
                          [diff]
                          tool = meld





                          share|improve this answer



























                            up vote
                            0
                            down vote













                            Combining what I learned in this thread and in this one, when I want to see "what is inside the stash", I first run:



                            git stash show stash@{0}


                            That will show what files were modified. Then, to get a nice visual diff in a difftool, I do:



                            git difftool --dir-diff stash@{0} stash@{0}^


                            This will display all the differences at once of the given stash against its parent.



                            You can configure the diff tool in ~/.gitconfig, e.g. with Meld:



                            ...
                            [diff]
                            tool = meld





                            share|improve this answer

























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              Combining what I learned in this thread and in this one, when I want to see "what is inside the stash", I first run:



                              git stash show stash@{0}


                              That will show what files were modified. Then, to get a nice visual diff in a difftool, I do:



                              git difftool --dir-diff stash@{0} stash@{0}^


                              This will display all the differences at once of the given stash against its parent.



                              You can configure the diff tool in ~/.gitconfig, e.g. with Meld:



                              ...
                              [diff]
                              tool = meld





                              share|improve this answer














                              Combining what I learned in this thread and in this one, when I want to see "what is inside the stash", I first run:



                              git stash show stash@{0}


                              That will show what files were modified. Then, to get a nice visual diff in a difftool, I do:



                              git difftool --dir-diff stash@{0} stash@{0}^


                              This will display all the differences at once of the given stash against its parent.



                              You can configure the diff tool in ~/.gitconfig, e.g. with Meld:



                              ...
                              [diff]
                              tool = meld






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited May 23 '17 at 11:47









                              Community

                              11




                              11










                              answered Oct 20 '15 at 12:24









                              Ferrard

                              385311




                              385311






















                                  up vote
                                  0
                                  down vote













                                  She the list of stash



                                  git stash list 
                                  stash@{0}: WIP on feature/blabla: 830335224fa Name Commit
                                  stash@{1}: WIP on feature/blabla2: 830335224fa Name Commit 2


                                  So get the stash number and do:



                                  You can do:



                                   git stash show -p stash@{1}


                                  But if you want a diff (this is different to show the stash, that's why I write this answer. Diff consider the current code in your branch and show just show what you will apply)



                                  You can use:



                                  git diff stash@{0}


                                  or



                                  git diff stash@{0} <branch name>


                                  Another interesting thing to do is:



                                  git stash apply
                                  git stash apply stash@{10}


                                  This applies the stash without removing it from the list, you can git checkout . to remove those change or if you are happy git stash drop stash@{10} to remove a stash from the list.



                                  From here I never recommend to use git stash pop and use a combination of git stash apply and git stash drop If you apply a stash in the wrong branch... well sometimes is difficult to recover your code.






                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    She the list of stash



                                    git stash list 
                                    stash@{0}: WIP on feature/blabla: 830335224fa Name Commit
                                    stash@{1}: WIP on feature/blabla2: 830335224fa Name Commit 2


                                    So get the stash number and do:



                                    You can do:



                                     git stash show -p stash@{1}


                                    But if you want a diff (this is different to show the stash, that's why I write this answer. Diff consider the current code in your branch and show just show what you will apply)



                                    You can use:



                                    git diff stash@{0}


                                    or



                                    git diff stash@{0} <branch name>


                                    Another interesting thing to do is:



                                    git stash apply
                                    git stash apply stash@{10}


                                    This applies the stash without removing it from the list, you can git checkout . to remove those change or if you are happy git stash drop stash@{10} to remove a stash from the list.



                                    From here I never recommend to use git stash pop and use a combination of git stash apply and git stash drop If you apply a stash in the wrong branch... well sometimes is difficult to recover your code.






                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      She the list of stash



                                      git stash list 
                                      stash@{0}: WIP on feature/blabla: 830335224fa Name Commit
                                      stash@{1}: WIP on feature/blabla2: 830335224fa Name Commit 2


                                      So get the stash number and do:



                                      You can do:



                                       git stash show -p stash@{1}


                                      But if you want a diff (this is different to show the stash, that's why I write this answer. Diff consider the current code in your branch and show just show what you will apply)



                                      You can use:



                                      git diff stash@{0}


                                      or



                                      git diff stash@{0} <branch name>


                                      Another interesting thing to do is:



                                      git stash apply
                                      git stash apply stash@{10}


                                      This applies the stash without removing it from the list, you can git checkout . to remove those change or if you are happy git stash drop stash@{10} to remove a stash from the list.



                                      From here I never recommend to use git stash pop and use a combination of git stash apply and git stash drop If you apply a stash in the wrong branch... well sometimes is difficult to recover your code.






                                      share|improve this answer












                                      She the list of stash



                                      git stash list 
                                      stash@{0}: WIP on feature/blabla: 830335224fa Name Commit
                                      stash@{1}: WIP on feature/blabla2: 830335224fa Name Commit 2


                                      So get the stash number and do:



                                      You can do:



                                       git stash show -p stash@{1}


                                      But if you want a diff (this is different to show the stash, that's why I write this answer. Diff consider the current code in your branch and show just show what you will apply)



                                      You can use:



                                      git diff stash@{0}


                                      or



                                      git diff stash@{0} <branch name>


                                      Another interesting thing to do is:



                                      git stash apply
                                      git stash apply stash@{10}


                                      This applies the stash without removing it from the list, you can git checkout . to remove those change or if you are happy git stash drop stash@{10} to remove a stash from the list.



                                      From here I never recommend to use git stash pop and use a combination of git stash apply and git stash drop If you apply a stash in the wrong branch... well sometimes is difficult to recover your code.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Sep 7 at 21:31









                                      Raúl Martín

                                      2,5511831




                                      2,5511831






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7677736%2fgit-diff-against-a-stash%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Contact image not getting when fetch all contact list from iPhone by CNContact

                                          count number of partitions of a set with n elements into k subsets

                                          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks