352

Is there a way to tell when a stash was created?

git stash list only lists the stashes, and git stash show XXXXXX shows all the files and changes, but not the date of the stash creation.

SQB
  • 3,926
  • 2
  • 28
  • 49
Jason Lawton
  • 4,412
  • 3
  • 21
  • 20

3 Answers3

545

Try:

git stash list --date=local

It should print something like:

stash@{Thu Mar 21 10:30:17 2013}: WIP on master: 2ffc05b Adding resource
Igor
  • 33,276
  • 14
  • 79
  • 112
  • 14
    Can I add an option somewhere in my .gitconfig to make this the default display? – Trevoke Oct 31 '13 at 18:13
  • 2
    @Trevoke Hm, not that I'm aware of. Best I could find was this nabble: http://git.661346.n2.nabble.com/git-stash-list-vs-non-default-log-date-setting-td5388522.html – Igor Oct 31 '13 at 18:22
  • 22
    I prefer `git stash list --date=relative`. Worth noting is that the `--date` is coming from the `git log` command, not `stash` itself, see here for possible `--date` values: http://stackoverflow.com/questions/7853332/git-log-date-formats – thnee Oct 21 '14 at 15:09
  • 9
    @Trevoke I added an alias `[alias] stashlist = "stash list --date=local" ` to my ~/.gitconfig file – user848337 Dec 12 '14 at 16:38
  • 9
    `git stash list --date=short` give you date only, in fixed width YYYY-MM-DD format that is easy to visually scan. – Tor Klingberg Jan 17 '17 at 16:38
  • 4
    Using this removes the ordinal number of the stash commit (e.g. `stash@{0}`). Is there a way to show the date together with the number? – Dr_Zaszuś Jan 25 '21 at 09:51
  • 5
    @Dr_Zaszuś You can use `git stash list --pretty=format:"%gd - %ci - %s"` – Fabio says Reinstate Monica Feb 08 '22 at 11:42
79

You can use --pretty=format to achieve this. For example, this produces a stash list that includes a relative time:

git stash list --pretty=format:"%C(red)%h%C(reset) - %C(dim yellow)(%C(bold magenta)%gd%C(dim yellow))%C(reset) %<(70,trunc)%s %C(green)(%cr) %C(bold blue)<%an>%C(reset)"

I have this set in the [alias] section of my ~/.gitconfig file, so that I can bind it to a simple sl command:

[alias]
        co = checkout
        lg = log --graph --pretty=format:\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset\" --abbrev-commit
        rl = reflog --pretty=format:\"%Cred%h%Creset %C(auto)%gd%Creset %C(auto)%gs%C(reset) %C(green)(%cr)%C(reset) %C(bold blue)<%an>%Creset\" --abbrev-commit
        sl = stash list --pretty=format:\"%C(red)%h%C(reset) - %C(dim yellow)(%C(bold magenta)%gd%C(dim yellow))%C(reset) %<(70,trunc)%s %C(green)(%cr) %C(bold blue)<%an>%C(reset)\"

(You can see that I also have similar markups for log and reflog)

Here's what it looks like: git stash list

If you want to show the actual date, rather than a relative time then replace %(cr) with %(ci).

Lee Netherton
  • 21,347
  • 12
  • 68
  • 102
26

git show stash@{0} also prints out the date, along with the other information.

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • 1
    Ah I was using the 6 character abbreviation, maybe that was the problem. I think it also threw an error when I tried that command, but I'm on windows, so that's a whole other problem :). – Jason Lawton Mar 21 '13 at 15:42
  • 4
    Ah, Windows. Trying to use git on Windows usually leads me towards wanting to defenestrate my laptop ;) – bcmcfc Mar 21 '13 at 15:44
  • 1
    Doesn't appear to print the date with Git 2.8.3. – Elijah Lynn Jun 19 '16 at 14:16
  • @ElijahLynn I don't have a 2.8.3. to test on but it prints a full commit on 2.9 – bcmcfc Jun 20 '16 at 07:37