1

I know

git stash branch branchname

creates a new branch using the most recent stash

and

git stash branch branchname stash@{index}

creates a new branch using a stash at a given index. But, is it possible to do something like this?

git stash branch branchname stashname

Note: This didn't work

git stash branch branchname stash^{/name}
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Adriang
  • 721
  • 1
  • 6
  • 12
  • What do you mean by "stashname"? The stash names *are* `stash@{}`. – torek Nov 19 '18 at 17:21
  • @torek A stash can be saved with a name, or more accurately, a message "git stash save "guacamole sauce WIP" and then applied using that message "git stash apply stash^{/guacamo}" as discussed here https://stackoverflow.com/questions/11269256/how-to-name-and-retrieve-a-stash-by-name-in-git. – Adriang Nov 19 '18 at 17:31
  • Ah. That's technically a *message*, not a name. It just goes into the commit message for the work-tree. Unfortunately, the answer to which you linked is also completely wrong. (See [this other answer](https://stackoverflow.com/a/51775672/1256452) to that same question, which appears to be correct.) – torek Nov 19 '18 at 17:39
  • That's why I included, "or more accurately, a message" comment :) In common usage, I'd heard stashes with messages referred to as "named stashes", with the understanding that under the covers, they are stashes with an associated message. Good point about that incorrect answer. So, if we can apply a stash by using the index position can we also do so by message? – Adriang Nov 19 '18 at 18:21
  • 1
    You can certainly do a search (using `git log -g --grep`) and use that to get the stash index or hash ID. You'll need the index, with the `stash@{number}` spelling, for operations that want to also *drop* the stash: the hash ID alone won't suffice here. Since `git stash branch` drops the stash, it needs the index. Very recent Git versions accept a raw number, e.g., `2` means `stash@{2}`, but for older Git compatibility, you might want to stick with the `stash@{...}` syntax for some time. – torek Nov 19 '18 at 18:47
  • I found a helpful comment in the other answer. I'm going to create an alias and use "git log -g stash --grep="message" --pretty=format:"%gd" Thanks @torek! – Adriang Nov 19 '18 at 21:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183911/discussion-between-adriang-and-torek). – Adriang Nov 19 '18 at 21:26

1 Answers1

0

git stash branch branchname stash^{/name} Or git stash branch stash@{1}

This command should works. The error from the duplication of branch name "already exist". Try to use new branch name and it will work.