Is it possible to preview stash contents in git?

后端 未结 16 1761
后悔当初
后悔当初 2020-12-02 03:34

I often put work away for later, then other stuff comes along, and a few weeks later, I want to inspect the stash, and find out what changes it would make if I applied it to

16条回答
  •  心在旅途
    2020-12-02 04:01

    First we can make use of git stash list to get all stash items:

    $git stash list
    stash@{0}: WIP on ...
    stash@{1}: WIP on ....
    stash@{2}: WIP on ...
    

    Then we can make use of git stash show stash@{N} to check the files under a specific stash N. If we fire it then we may get:

    $ git stash show stash@{2}
    fatal: ambiguous argument 'stash@2': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git  [...] -- [...]'
    

    The reason for this may be that the shell is eating up curly braces and git sees stash@2 and not stash@{2}. And to fix this we need to make use of single quotes for braces as:

    git stash show stash@'{2'}
    com/java/myproject/my-xml-impl.xml                     | 16 ++++++++--------
    com/java/myproject/MyJavaClass.java                    | 16 ++++++++--------
    etc.
    

提交回复
热议问题