1

currently I got a few modified files into my local branch:

modified: commands/abc/Test.cs modified: common/des/Info.cs modified: common/pit/Abc.cs modified: services/Services123.cs 

I want to put to stash just first 3. How can I do that?

0

1 Answer 1

2

You can explicitly list files to stash after --

git stash -- commands/abc/Test.cs common/des/Info.cs common/pit/Abc.cs

Then your changes in services/Services123.cs won't be stashed.

(Note that in your specific case you could conveniently take advantage of the file names and use a wildcard, like git stash -- com*)

Sign up to request clarification or add additional context in comments.

6 Comments

what if I have all my files added to stage? And then I want to all files from stage put to stash?
@4est You can then use another flag, --keep-index, but warning : there's no --stash-index-only counterpart to do what you want. You'll have to 1) git stash --keep-index to save unstaged changes, then 2) do a regular git stash which will contain only your staged files, and finally recover in the working tree what you first stashed, with git stash pop stash{1}. At the end of this (slightly clunky) process, all your staged changes are stashed in stash{0}, and the other changes are in the working tree, waiting to be staged/discarded.
thx, so then I need to do: 1) git stash --keep-index 2) git stash push -m "my_new_stash"
Yes, if you prefer to refer to your (unstaged changes) stash by a name handle rather than by its stash number like I did. Both work. (If you're unsure, try it on a test repo, it's very quick to setup with just a couple of text files.)
last qq: instead of point 2) git stash push -m "my_new_stash"....what else I can do ?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.