As mentioned in this post
To put it another way, if you have the following in your .gitignore:
/my-ignored-directory/*
Then you’re screwed – after a git stash save -u, my-ignored-file.txt will be gone (and sorry, it’s not in the stash you just created either). Break out the undelete packages and hope for the best. Alternatively, if you have the following in your .gitignore:
/my-ignored-directory
Then you’re golden – no worries, kick back, relax, my-ignored-file.txt will stay exactly where it was prior to the git stash save -u.
Why is this difference? I'm also wondering if no files will be deleted if in my .gitignore
file I have /my-ignored-directory/
(with trailing slash)?
Results of both you examples will be the same, ignored files are gone. There is of course solution for it described in documentation:
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. If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.
Git internally calls git clean -d to put working directory in a very clean state.
Command that you want is:
git stash --include-untracked --all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With