72

I would like to see all stashes in git log output. Does anyone know if there is a way to do that?

Edit: I want to see all commits in the log -- including stash commits. I tried the command:

git log --date-order --all

But it returns only the top most stash. I would like to see commits that represent other stashes too.

idbrii
  • 10,975
  • 5
  • 66
  • 107
jbialobr
  • 1,382
  • 1
  • 13
  • 14

8 Answers8

59

You can show all your stashes with git stash list. Maybe you can write a script to show both git stash list and git log and use it with an alias.

mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81
54

I came here looking to do the same as @jbialobr, I did some more digging after reading the previous answers and came up with the below.

@msmt's answer gives you a log of the stashes, and you can use this to get the hashes to use in the git log.

git reflog show --format="%h" stash gives you just the hashes of all stashes which can then be passed to a git log command such as

git log --date-order --all $(git reflog show --format="%h" stash)

The full command I personally am now using is

git log --oneline --graph --decorate --all $(git reflog show --format="%h" stash)

Tested on git version 2.5.1 on centos

SicoAnimal
  • 556
  • 5
  • 2
  • 8
    SicoAnimal, you're an awesome human. Your only contribution to SO, with [until now; for over a year] 0 votes, is definitely one for the config file. Thank you! – OJFord Apr 14 '16 at 13:50
  • 1
    I would use xargs with this as it's more readable and easier to work with: ```git reflog show --format="%h" stash | xargs git show``` – joachim Mar 03 '19 at 11:34
  • This does show the stashes as part of the output, but there are no labels except for the first one, so it's hard to find them in the log. – Ken Williams Jun 06 '22 at 20:25
22

Not sure what you mean. stash is a branch and you can list all stashes with git log -g stash.

aerin
  • 20,607
  • 28
  • 102
  • 140
robinr
  • 4,376
  • 2
  • 20
  • 18
  • Better, it shows all stashes, but now it doesn't show index and untracked files commits that are related to stashes. Command git log -z --all --boundary shows them, but when I add -g stash, then these commits are no longer in log output. – jbialobr Feb 21 '13 at 19:47
  • 2
    Just spelling this out a bit more: `stash` is short for `refs/stash` the list of all of the stash heads, and `-g` (or `--walk-refs`) tells `log` to step through the items in the reference list, rather than following the modification history back from each stash commit. – Joshua Goldberg Oct 25 '20 at 15:52
7

Another easy way to do this is git reflog show stash

Michael
  • 308
  • 3
  • 12
  • Have you read my Edit note? I know how to list stashes. I would like to include the all stashes in the output of the `git log` command. – jbialobr Mar 07 '15 at 11:08
  • 1
    @jbialobr I guess your question was a bit ambiguous to me. It looked like you knew how to log all the commits but you were looking for how to see just stashes. The ambiguity for me is at, `I would like to see commits that represent other stashes.` If `git log --all` is not working for you then I would have to second what @robinr said, "Not sure what you mean". – Michael Mar 08 '15 at 21:57
4

For git version 2.2.3 or later, you can simply use the --reflog option of git log.

git log --graph --oneline --all --reflog

In addition, it also shows dangling commits.

M Imam Pratama
  • 998
  • 11
  • 26
3

To get the tree graph with everything: all branches, all stashes at your fingertips...


Expanding on a super-useful answer from SicoAnimal, so you don't have to type out all this stuff (especially useful with remote SSH sessions where you don't have any kind of Git UI)...


1. Setup git aliases:

# Short and sweet: hashes and graph with all branches and stashes
git config --global alias.l \
    '!sh -c '"'"' git log --oneline --graph --all --decorate $(git reflog show --format="%h" stash --) '"'"' '

# Same as above + dates and emails
git config --global alias.ll \
    '!sh -c '"'"' git log --graph --all --date=format:"'"%Y-%m-%d %H:%M"'" --pretty=format:"'"%C(yellow)%h%Creset%C(auto)%d%Creset %C(cyan)%cd%Creset %s %C(green)(%ce)%Creset"'" $(git reflog show --format="%h" stash --) '"'"' '

2. Use aliases:

# Short and sweet: hashes and graph with all branches and stashes
git l

# Same as above + dates and emails
git ll

3. Sweet result:

Notice that you can see all stashes, not only the latest one on a the given commit (shown with arrows).

enter image description here


Room for improvement:

# In case there are no stashes you get one-liner error message.
# The rest works as expected. Not sure how to fix it.
me@mymachine:~/projects/experiment/latest-angular-ten$ git l
fatal: bad revision 'stash'
* 00a696b (HEAD -> master) initial commit


References:

How to create a Git alias with nested commands with parameters?

Andrei Sinitson
  • 739
  • 6
  • 10
2

Full command:

git log --oneline --graph --all $(git stash list --format="%H")

Where list of heads of stashes:

git stash list --format="%H"

0

If you can afford having a graphical GUI, take a look at gitk.

It shows you branches, tags, remote branches stashes etc. In a visually not appealing, but very compact and useful form. It usually comes along with "git" package in your package manager and works if you also have "tk" (the GUI toolkit it uses).

VasiliNovikov
  • 9,681
  • 4
  • 44
  • 62
  • It shows only the topmost stash by default. If you have a way to make it show more than that, I'd love to hear about it. – Neil Mayhew Jun 22 '20 at 15:42