Show all stashes in git log
Asked Answered
G

8

74

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.

Gerius answered 20/2, 2013 at 20:6 Comment(0)
E
56

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

Endlong answered 14/3, 2016 at 16:53 Comment(3)
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!Celestyn
I would use xargs with this as it's more readable and easier to work with: git reflog show --format="%h" stash | xargs git showJennettejenni
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.Councillor
S
64

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.

Semiology answered 20/2, 2013 at 20:32 Comment(0)
E
56

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

Endlong answered 14/3, 2016 at 16:53 Comment(3)
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!Celestyn
I would use xargs with this as it's more readable and easier to work with: git reflog show --format="%h" stash | xargs git showJennettejenni
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.Councillor
M
23

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

Maurene answered 20/2, 2013 at 20:11 Comment(2)
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.Gerius
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.Hydrolyze
F
7

Another easy way to do this is git reflog show stash

Fissure answered 5/3, 2015 at 16:37 Comment(2)
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.Gerius
@Gerius 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 @Maurene said, "Not sure what you mean".Fissure
R
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.

Remodel answered 21/1, 2022 at 3:52 Comment(0)
C
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 stash list --format="%h") '"'"' '

# 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 stash list --format="%h") '"'"' '

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


References:

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

Cheapen answered 18/12, 2020 at 15:16 Comment(2)
If you use git stash list --format=%H (as suggested in a comment above by @tangle) you won't have the problem when there are no stashesJecho
Nice! Thanks for the tip! Updated my answer: now it uses git stash list.Cheapen
H
2

Full command:

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

Where list of heads of stashes:

git stash list --format="%H"

Hinson answered 21/2, 2019 at 13:29 Comment(0)
L
1

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).

Lotte answered 12/2, 2019 at 8:1 Comment(2)
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.Jecho
@NeilMayhew, try setting View Menu -> Edit View... -> Command to generate more commits to include to git stash list --format=%H.Haynie

© 2022 - 2024 — McMap. All rights reserved.