ziemowit141
ziemowit141

Reputation: 615

How to add file to existing stash in git?

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?

Upvotes: 22

Views: 11498

Answers (2)

Saurabh P Bhandari
Saurabh P Bhandari

Reputation: 6762

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)

Upvotes: 3

Ondrej K.
Ondrej K.

Reputation: 9679

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?

Upvotes: 22

Related Questions