Change Git stash message

GitGit Stash

Git Problem Overview


I have a stash saved for the future that I want to give a meaningful name. While it's possible to pass a message as argument to git stash save, is there a way to add a message to an existing stash?

Git Solutions


Solution 1 - Git

You can directly edit the messages stored in .git/logs/refs/stash.

I know it's probably not ideal, but should work anyway.

Solution 2 - Git

Yep, there is a way, you can try this:

git stash store -m "your descriptive message here" stash@{1}

This will create a new Stash named stash@{0} with the message as above.
This Stash is same as stash@{1}.

Then you can remove the old stash@{1} above with:

git stash drop stash@{2} # the stash@{1} has become stash@{2} as a new stash has been created.

NOTE: you cannot do this with stash@{0}: git stash store -m "message here" stash@{0} will do nothing.

Solution 3 - Git

(Expanding on manojlds's answer.) The simplest thing to attach a message is indeed to un-stash and re-stash with a message, there is a git stash branch command that will help you doing this.

git stash branch tmp-add-stash-message
git stash save "Your stash message"

The only drawback is that this stash now appears to originate from the tmp-add-stash-message branch. Afterwards, you can checkout another branch and delete this temporary branch.

Of course, this assumes that your working copy is clean, otherwise you can stash the current changes :-)

Solution 4 - Git

Not without popping and saving again.

Solution 5 - Git

Here's some commands to help you pop and save again as @manojlds suggests:

git stash #save what you have uncommitted to stash@{0}
git stash pop stash@{1} #or another <stash> you want to change the message on
# only if necessary, fix up any conflicts, git reset, and git stash drop stash@{1}
git stash save "new message"
git pop stash@{1} #get back to where you were if you had uncommitted changes to begin with

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCharlesBView Question on Stackoverflow
Solution 1 - GityibeView Answer on Stackoverflow
Solution 2 - GitRyan LeView Answer on Stackoverflow
Solution 3 - GitkrlmlrView Answer on Stackoverflow
Solution 4 - GitmanojldsView Answer on Stackoverflow
Solution 5 - GitJayenView Answer on Stackoverflow