更改 Git 隐藏消息

我存了一些钱以备将来用我想给它们起个有意义的名字。虽然可以将消息作为参数传递给 git stash save,但是有没有一种方法可以将消息添加到现有的存储中?

22206 次浏览

Not without popping and saving again.

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

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

(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 :-)

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

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.