Jason Lawton
Jason Lawton

Reputation: 4672

Get the creation date of a stash

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.

Upvotes: 378

Views: 68158

Answers (3)

Lee Netherton
Lee Netherton

Reputation: 22552

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

Upvotes: 94

bcmcfc
bcmcfc

Reputation: 26815

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

Upvotes: 29

Igor
Igor

Reputation: 34011

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

Upvotes: 588

Related Questions