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

前端 未结 5 1500
没有蜡笔的小新
没有蜡笔的小新 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 06:55

    Untracked files are stored in the third parent of a stash commit. (This isn't actually documented, but is pretty obvious from The commit which introduced the -u feature, 787513..., and the way the rest of the documentation for git-stash phrases things... or just by doing git log --graph stash@{0})

    You can view just the "untracked" portion of the stash via:

    git show stash@{0}^3
    

    or, just the "untracked" tree itself, via:

    git show stash@{0}^3:
    

    or, a particular "untracked" file in the tree, via:

    git show stash@{0}^3:
    

    There is, unfortunately, no good way to get a summary of the differences between all staged+unstaged+untracked vs "current" state. ie: git show stash@{0} cannot be made to include the untracked files. This is because the tree object of the stash commit itself, referred to as stash@{0}:, does not include any changes from the third, "unstaged" parent.

    This is due to the way stashes are re-applied: tracked files can be easily applied as patches, whereas untracked files can only be applied, in theory, as "whole files".

提交回复
热议问题