How to add file to existing stash in git?

Viewed 3126

When I did git stash push <path/to/file> it created stash@{0} for it. Reusing the same command with different file creates another stash -> stash@{1}. I have other files that logically belong to stash@{0}.

Can I somehow push file to existing stash?

2 Answers

If you mean akin to git commit --amend, I am afraid you are out of luck, but would it be acceptable for your use case, to:

git stash pop

and then

git stash push ORIGINAL_FILES MORE_FILES

to have the files grouped?

As per git docs,

<stash>

This option is only valid for apply, branch, drop, pop, show commands.

A reference of the form stash@{<revision>}. When no <stash> is given, the latest stash is assumed (that is, stash@{0}).

So you can't do this directly using push command of git stash.

Probably use this git stash push <path/to/file1> <path/to/file2> ... next time as push accepts multiple pathspecs (filenames)

Related