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

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

    You can list all stash commits with the following command:

    git rev-list -g stash
    

    Since stashes are represented as a 3-way merge commit of HEAD, the index, and a parent-less "root" commit of untracked files, untracked file stashes can be listed by piping the above output into the following:

    git rev-list -g stash | git rev-list --stdin --max-parents=0
    

    Useful applications of the above:

    Show only untracked, stashed files

    git rev-list -g stash | git rev-list --stdin --max-parents=0 | xargs git show --stat
    

    Of course, remove the --stat to see the contents of the files.

    Find a specific file

    git rev-list -g stash | xargs -n1 git ls-tree -r | sort -u | grep 
    

    Grep untracked files

    git rev-list -g stash | git rev-list --stdin --max-parents=0 | xargs git grep 
    

    List all contents of all stashes

    git rev-list -g stash | git rev-list --stdin | xargs git show --stat
    

提交回复
热议问题