How to stash a specific file or multiple files?
For further actions, you may consider blocking this person and/or reporting abuse
How to stash a specific file or multiple files?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (11)
This didn't work:
git stash _file_This did:
git stash push _file_ --keep-indexgit stash- e.g.git stash .orgit stash src/index.js. Thengit stash applyto apply the stashed changes orgit stash dropto discard them.Is that what you're looking for?
git stash popis like apply + drop as well. I thinkgit stash --keep-indexkeeps everything staged, and stashes unstaged changes. Useful if it's hard to type the pathspec for multiple files, or if you want to stash some changes to a file but not all.Big fan of
git stash pop. Definitely a1 command > 2 commandsscenario.Whoa, TIL. Git's pretty cool, isn't it
Yup. Cool π
What does
-p -uflag does?git stash --keep-indexit is.Add the changes to the staging area which you do not want to stash. All changes to be stashed should be not staged but modified or untracked. Then you can just
git stash --keep-indexto stash changes. As mentioned in some other answer, add-uto add untracked files also. Then you can justgit restore --staged <file names>to bring staged changes back to modified.I suggest git stash save "a comment here". I always use it, it is the best way or working with stashes, the indexes may get you lost
Just to help people coming from google the save command has been deprecated:
This option is deprecated in favour of git stash push. It differs from "stash push" in that it cannot take pathspecs, and any non-option arguments form the message.