15

Is there a maximum number of git stashes, or can you have as many as you like?

I'm aware that

git stash list

doesn't list as many results as

git stash list --date=local

But does Linus Torvalds think that anyone with more than x stashes is an idiot who deserves to lose the old stashes?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
  • 5
    Um, what's Linus Torvalds' opinion got to do with anything? – CB Bailey Jan 05 '11 at 01:20
  • 1
    If you have a large number of stashes perhaps some of them should be named branches instead. – Adam Vandenberg Jan 05 '11 at 01:21
  • Are you sure you're not just seeing git's default behavior of adding $PAGER to anything with enough output to scroll the screen? – Ben Jackson Jan 05 '11 at 01:24
  • 1
    @Charles a lot of git's design is based on the opinions of Linus Torvalds. – Laurence Gonsalves Jan 05 '11 at 01:36
  • 1
    @Laurence Gonsalves: Linux Torvalds didn't write `git-stash`, wasn't the maintainer of git when it was integrated into the git source tree and hasn't, to my knowledge, ever contributed to `git-stash` so I don't see how any opinions he may or may not have on its usage are relevant to its current behaviour. – CB Bailey Jan 05 '11 at 01:58
  • 2
    @Charles That's all good to know, and it probably would have been more productive to make that your first comment. Given what you know about git's history it should be pretty obvious to you how someone who didn't know quite as much about it might think that git-stash's behavior was influenced by Linus's opinions, as so much of the rest of git has been. – Laurence Gonsalves Jan 05 '11 at 02:34
  • There is no reason for any limit here. – user562374 Jan 05 '11 at 18:25
  • Regardless, Linus may have an opinion – Kirby Apr 23 '14 at 15:42

2 Answers2

23

There is no hard limit to stashes. Stashes are simply implemented using the reflog of a specially-named ref called stash.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • Does this mean they're liable to be deleted if you do `git prune` or `git gc`? – Andrew Grimm Jan 05 '11 at 02:31
  • Ya know, I'm not sure. In general, the reflog lasts for 90 days (or 30 days for unreachable commits). I would expect that git doesn't apply this limit to the stash, but I can't be certain. – Lily Ballard Jan 05 '11 at 04:33
  • 3
    I just checked the source, it does indeed appear to handle the stash specially. – Lily Ballard Jan 05 '11 at 04:33
11

No, there's no limit. In fact, Git handles large numbers of stashes quite gracefully:

$ du -sh .git; \
> for i in {1..10000}; do echo $i > README; git stash -q; done; \
> git gc -q; du -sh .git; time git stash list | wc -l
8.5M     .git
13M      .git        # space efficient
10000                # all there
real     0m0.212s    # listing 10,000 entries
$ echo foo > README; time git stash -q; time git stash pop -q
real     0m0.159s    # save still fast
real     0m0.146s    # pop still fast

I didn't test more, but I'd assume it'll still work the same for 100,000 or a million. So yes, the number of stashes really is unlimited.

Jo Liss
  • 30,333
  • 19
  • 121
  • 170