So, I'm not sure why there's so much consternation on this topic. I can name a git stash
with both a push
and the deprecated save
, and I can use a regex to pull it back with an apply
:
Git stash method to use a name to apply
$ git stash push -m "john-hancock"
$ git stash apply stash^{/john-hancock}
As it has been mentioned before, the save
command is deprecated, but it still works, so you can used this on older systems where you can't update them with a push
call. Unlike the push
command, the -m
switch isn't required with save
.
// save is deprecated but still functional
$ git stash save john-hancock
This is Git 2.2 and Windows 10.
Visual Proof
Here's a beautiful animated GIF demonstrating the process.
Sequence of events
The GIF runs quickly, but if you look, the process is this:
- The
ls
command shows 4 files in the directory
touch example.html
adds a 5th file
git stash push -m "john-hancock" -a
(The -a
includes untracked files)
- The
ls
command shows 4 files after the stash, meaning the stash and the implicit hard reset worked
git stash apply stash^{/john-hancock}
runs
- The
ls
command lists 5 files, showing the example.html file was brought back, meaning the git stash apply
command worked.
Does this even make sense?
To be frank, I'm not sure what the benefit of this approach is though. There's value in giving the stash a name, but not the retrieval. Maybe to script the shelve and unshelve process it'd be helpful, but it's still way easier to just pop a stash by name.
$ git stash pop 3
$ git stash apply 3
That looks way easier to me than the regex.