6

git stash doesn't show untracked files after I use git stash save -u:

D:\kzxd-usm\KzxdUsm>git status
Already up-to-date!
# On branch work
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       WebRoot/WEB-INF/jsp/usm/org/Copy of list.jsp
nothing added to commit but untracked files present (use "git add" to track)

I want list the untracked file after it's stashed with git stash save -u:

D:\kzxd-usm\KzxdUsm>git stash list --stat
stash@{0}: On work: hide copy of list.jsp

It has only a little comment text and does not have stashed file information.

Big McLargeHuge
  • 14,841
  • 10
  • 80
  • 108
lyrl
  • 122
  • 1
  • 5
  • This question is hard to understand... – deivid Jul 16 '15 at 12:10
  • lyrl obviously doesn't write english very well. I think it is quite cruel to downvote them because of that. Instead it would have been nicer to try and help extract what they are trying to say. I could easily work out that they are saying "'git stash show' doesn't show untracked files". Its a valid question. I'm upvoting it. – HankCa Nov 16 '16 at 02:38
  • Possible duplicate of [In git, is there a way to show untracked stashed files without applying the stash?](https://stackoverflow.com/questions/12681529/in-git-is-there-a-way-to-show-untracked-stashed-files-without-applying-the-stas) – Big McLargeHuge Jun 09 '17 at 16:09

5 Answers5

6

use git show stash@{0}^3 to show all the untracked files stashed.

nakeer
  • 641
  • 1
  • 9
  • 17
2

In my 1.7.8.2, stash@{0}^3 does not work to show untracked files. However, I have found that the following does list them in the the second log entry:

git log -2 --name-only stash@{0}

You can use -p instead of --name-only if you want to see the file details.

David
  • 21
  • 1
1

If you stash with git stash save -u and then do git stash show, untracked files will not be shown -- the listing will contain changes to tracked files only.

It makes sense when you want to share your stashed changes with someone: The diff you get from git stash show won't contain any extra garbage (the untracked stuff from your working copy) but only the relevant changes to tracked files.

Once you restore your stashed changes with git pop, the untracked files will be restored as well.

huoneusto
  • 1,164
  • 1
  • 8
  • 19
  • 3
    I dont' think this behaviour makes sense at all. Stashes are private (can you share them???). That issue just freaked me out as I thought I'd somehow lost all the work I had done last week ("damm I must have rebased them out of existence"). Ideally I would interim commit work, though sometimes I just reach for the 'ole `stash` command without thinking. – HankCa Nov 16 '16 at 02:45
  • Afaik, they're completely private/local. By sharing I meant sharing the plain diff/patch -- via copying, emailing or by other means. – huoneusto Nov 28 '16 at 08:31
  • 1
    Yep, it doesn't make sense. On git [mailing list](https://public-inbox.org/git/20170317141417.g2oenl67k74nlqrq@sigill.intra.peff.net/) I found: "I don't think there is a good reason. The "untracked" option was added to git-stash much later, and nobody considered how it interacted with "stash show"." – Mariusz Pawelski Apr 28 '20 at 12:04
1

The best answer I found is at In git, is there a way to show untracked stashed files without applying the stash? and this answer in particular - https://stackoverflow.com/a/23712152/1019307.

git rev-list -g stash | git rev-list --stdin --max-parents=0 | xargs git show --stat
Community
  • 1
  • 1
HankCa
  • 9,129
  • 8
  • 62
  • 83
0

git stash will only stash changes in files that git knows about: it won't stash changes in untracked files.

You can tell git about the file using git add, then stash the changes using git stash:

git add Copy\ of\ list.jsp
git stash
simont
  • 68,704
  • 18
  • 117
  • 136
  • 2
    True but the `-u/--include-untracked` will add them. Often you want to stash untracked files. The question was asking how to show untracked stashed files. That issue just freaked me out as I thought I'd somehow lost all the work I had done last week ("damm I must have rebased them out of existence"). I don't like this behaviour of not showing untracked stashed files. – HankCa Nov 16 '16 at 02:43