In git, is there a way to show untracked stashed files without applying the stash?

前端 未结 5 1497
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 06:28

If I run git stash -u, I can stash untracked files. However, said untracked files don\'t show up at all with git stash show stash@{0}. Is there

5条回答
  •  天命终不由人
    2020-12-04 07:00

    To list the untracked files in the stash:

    git ls-tree -r stash@{0}^3 --name-only
    

    To show a complete diff of all untracked files (with content):

    git show stash@{0}^3
    

    These commands read the last (most recent) stash. For earlier stashes, increment the number behind the "stash@", for example stash@{2} for the second from the last stash.

    The reason this works is that git stash creates a merge commit for each stash, which can be referenced as stash@{0}, stash@{1} etc. The first parent of this commit is the HEAD at the time of the stash, the second parent contains the changes to tracked files, and the third (which may not exist) the changes to untracked files.

    This is partly explained in the manpage under "Discussion".

提交回复
热议问题