Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Rename stashes #218

Closed
fbartho opened this issue Feb 16, 2018 · 17 comments
Closed

[Feature Request] Rename stashes #218

fbartho opened this issue Feb 16, 2018 · 17 comments
Milestone

Comments

@fbartho
Copy link

fbartho commented Feb 16, 2018

Right-click menu on stash entries allows user to Apply a stash or Delete a stash, (which I was happy to discover).

It'd be nice if there was a built-in helper that would rename stashes as well.

@nebhale
Copy link

nebhale commented Feb 16, 2018

Great idea since whenever I create stashes at the command line, I always forget to give them names.

@fbartho
Copy link
Author

fbartho commented Feb 16, 2018

@nebhale that’s exactly my usecase too!

@DanPristupov
Copy link
Contributor

I made some research and I could not find any easy way to rename a stash. Any idea how this could be done?

@fbartho
Copy link
Author

fbartho commented Feb 20, 2018

My old hack: Apply, stash save w/ name, delete old stash.
Note: this makes a fresh stash at the top of the stack, so your stashes get reordered :(

@DanPristupov
Copy link
Contributor

@fbartho it also requires user to have clean working directory :(.

There's a hack: https://stackoverflow.com/questions/25931026/how-can-i-rename-a-git-stash#35549615. But it does not really rename stash, it only changes reflog message. In this way new message will be displayed when you call git stash list, but all git clients will still show the old title.

@fbartho
Copy link
Author

fbartho commented Feb 21, 2018

Oh! I found git stash store https://stackoverflow.com/a/35549615

@davecotter
Copy link

why is this closed? it is a legit feature request with a defined solution?

@DanPristupov
Copy link
Contributor

This is a legit feature request, but I don't know a way to rename a stash. I think currently it's simply not possible.

@brechtm
Copy link

brechtm commented Jan 8, 2021

I think have I figured out a way to do this. I have described it in this StackOverflow answer.

Fork does have an issue with the newly created stash, however. The first character of the stash message is missing. The GitLens VSCode plugin does show the stash message properly in its list of stashes, however.

Related to this, I noticed that Fork hides the On <branch-name>: prefixed to the user-supplied stash message. I assume this is what is causing the missing character. I'm would vote to not remove this however, since this can be quite useful information.

@DanPristupov
Copy link
Contributor

@brechtm this looks like a correct approach. I will have a look.

Just a note: a stash can have 3 parents when it's created with the --keep-index option.

@brechtm
Copy link

brechtm commented Jan 8, 2021

Just a note: a stash can have 3 parents when it's created with the --keep-index option.

Thanks for the heads-up. I've now mentioned that in the SO answer.

@DanPristupov DanPristupov reopened this Jan 11, 2021
@DanPristupov DanPristupov changed the title Feature Idea: Helper to rename stashes [Feature Request] Rename stashes Jan 11, 2021
@DanPristupov
Copy link
Contributor

Alright, we have a working version! Would you like to try it?

https://cdn.fork.dev/mac/Fork-2.2.3.dmg

The usage is simple, stash rename is available in the context menu in the commit list and on the sidebar.

Screenshot 2021-01-11 at 17 51 23

@fbartho
Copy link
Author

fbartho commented Jan 11, 2021

@DanPristupov I was able to test it! and it worked!

Nuance for anybody surprised -- when you rename a stash, it moves to the top of the stack, but that's an acceptable detail imho.

@brechtm
Copy link

brechtm commented Jan 11, 2021

Alright, we have a working version! Would you like to try it?

Yup, works great!

Nuance for anybody surprised -- when you rename a stash, it moves to the top of the stack, but that's an acceptable detail imho.

I would also prefer that the ordering to stay the same. If the stashes are sorted by date, the original stash commit's timestamp could perhaps be copied?

@fbartho
Copy link
Author

fbartho commented Jan 11, 2021

@brechtm I believe the stashes are numbered / ordered automatically (not dynamically sorted based on any particular criteria).

It wouldn't surprise me if it were impossible to rename "in-place" without changing the order.

@brechtm
Copy link

brechtm commented Jan 11, 2021

@fbartho Ah yes, I forgot the stashes are part of a stack, and numbered based on their position.

Poking around a bit, I learned that the stash list is basically shoehorned into a reflog. I was able to reorder the stashes by swapping lines of .git/logs/refs/stash. In that sense, the git stash store step could be replaced by editing the appropriate line of that file: replacing the stash message and commit ID (which is also used in the next entry on the stash stack!).

Editing that file may not be a good idea though. Perhaps it's possible to edit one of the entries in this file using plumbing commands?

In any case, even with the renamed stash jumping to the top, this is still a very useful feature to have as-is. Much appreciated, @DanPristupov! Perhaps in-place renaming (and arbitrary stash reordering?) can be added at a later point in time.

@wardboumans
Copy link

Please add the F2 shortcut to be consistent with branch renaming.

@DanPristupov DanPristupov added this to the 2.4 milestone Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants