25

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?

asked Apr 1, 2020 at 11:17
2
  • 3
    While creating the stash you could have done, git stash push <path/to/file1> <path/to/file2>, push takes multiple files Commented Apr 1, 2020 at 11:24
  • 1
    A Git stash is just a little clump of commits that aren't on any branch. As with any commit, you cannot change anything about it once it's made. All you can do is make a new, different commit—or in this case, a new, different stash—that has the content you want, and stop using the old one. I generally recommend avoiding git stash: just make normal commits instead. Commented Apr 1, 2020 at 18:08

2 Answers 2

25

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?

answered Apr 1, 2020 at 11:43
Sign up to request clarification or add additional context in comments.

1 Comment

By default pop command will pop 0th stash i.e. stash@{0} so to pop first nth stash git stash pop stash@{n} and then git stash push -m "useful message" <path-spec-including-old-and-new-files>
2

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)

answered Apr 1, 2020 at 11:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.