2018-08-13 A tip on git stash

Last edit

Summary: +comment about comment

Added:

> /Edit:/ there is a nice tip for Magit users in the [[Comments_on_2018-08-13_A_tip_on_git_stash|comment]].


I don’t know about you, but I use git stash fairly often. (This might be just a bad habit, and committing might be a better idea, but I do find stashing useful, especially for minor changes I’d like to apply from time to time on different branches but never commit. Yes, console.log and friends, I’m looking at you, but also at turning on various “debug” variables.)

After some time, git stash list begins to look like this:

stash@{0}: On master: zzz
stash@{1}: On some_branch: change something
stash@{2}: On some_other_branch: zzz
stash@{3}: On some_other_branch: abandoned wip
stash@{4}: On some_other_branch: zzzzzzz
stash@{5}: On some_other_branch: zzz
stash@{6}: On some_other_branch: wip
stash@{7}: On yet_another_branch: zzz
stash@{8}: On and_another: zzz
stash@{9}: On develop: improve (?) watching
stash@{10}: On and_one_more: left outer join experiment (to delete)
stash@{11}: On and_more: to_delete
stash@{12}: On dont_you_have_enough: wip2
stash@{13}: On dont_you_have_enough: wip
stash@{14}: On no_i_dont: to_delete
stash@{15}: On this_starts_to_get_boring: to_delete
stash@{16}: On develop: zzz
stash@{17}: On but_who_cares: d3
stash@{18}: On master: zzz
...

Please don’t laugh at me too hard – I know this is terrible (and 100% real – I changed the names, of course, and actually made the list shorter (!), but it’s really what I have.)

It would be probably easier to decide which stashes can be safely dropped if you could list their timestamps instead of numbers.

But hey, this is Git, and that should be possible, no?

The git-stash manual entry says under git stash list:
The command takes options applicable to the git log command to control what is shown and how. See git-log(1).
And if you look at git-log manpage, you will find the --date=<format> option.

So, why don’t we try git stash list --date=iso?

stash@{2018-08-09 11:03:21 +0200}: On master: zzz
stash@{2018-07-27 10:55:35 +0200}: On some_branch: change something
stash@{2018-07-19 16:26:11 +0200}: On some_other_branch: zzz
...

Or how about git stash list --date=relative?

stash@{4 days ago}: On master: zzz
stash@{2 weeks ago}: On some_branch: change something
stash@{4 weeks ago}: On some_other_branch: zzz
...

Other interesting options include short (only date, not the time), format:... (almost anything that strftime can parse) and local. See the manpage of git-log for the details.

Actually, if you have some spare time, reading through git-stash manpage is a thrilling experience. For instance, the way stashes are kept is a clever trick, and I can’t yet decide whether it’s a compliment or otherwise…

Edit: there is a nice tip for Magit users in the comment.

CategoryEnglish, CategoryBlog, CategoryGit