JMarsch JMarsch - 9 months ago 62
Git Question

git stash does not save newly added files

I am using Visual Studio 2015 and Git, and I noticed some behavior with the git stash command that I did not expect:

I had some changes that I wanted to stash. The changes included a new .cs file that I had added to my project using the Visual Studio UI.

The changes window in Visual Studio showed my file as an add, but when I executed git stash save, and then git stash show, the listing included only my modified files, and not my added file. My added file remained in the Changes window as an (add)

Is there a way to use git stash and have it pick up the files that I have added with Visual Studio?

I have seen the --all and --include untracked options, but if I use those, would they cause git to also save my build artifacts, my node_modules, and packages folders?


git stash only stashes tracked files (eg files that already have been added to the repository)

The right option to use is --include-untracked :

From git help stash

If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state.

An other way is to manually track files (that's what I usually do to not have to remember yet another option) :

git add . 
git stash