Reputation: 1121
I have added some new files in the repository. Made some changes to existing files , deleted few files etc..
when I issue "git stash"
, I expect all my local changes to be reverted and I should have clean working copy of my remote repo. But the files I have added newly are still showing up in the "git status". I have deleted the files manually.
why is it so? Do i have to issue "git reset"
?
To replicate:
Assuming abc.txt is new file created. When I do "git stash" , the file is still present.
Upvotes: 1
Views: 1671
Reputation: 4926
You can use reset
but then your changes will be lost & change of mind won't do you any good but with stash
you can get them back using git stash pop
.
Reason for why git stash doesn't stash untracked files:
By default, running git stash will stash:
But it will not stash:
So now the question remains: how does one use git stash.
TL;DR Two ways to use stash
Add the -u option (or --include-untracked) tells git stash to also stash your untracked files so that our command becomes
git stash -u
You can include changes to ignored files as well by passing the -a option (or --all) when running git stash & our command takes the shape
git stash -all
Check out this article for more details.
Upvotes: 1
Reputation: 695
I think this might help you.
New files are untracked, and by default, git stash
will not include them. So, you need to run git stash --include-untracked
or git stash --all
to stash everything.
Be aware that you might end up stashing ignored files with git stash --all
command.
Another way (maybe easier) to solve this problem is to move unstaged changes to stage area:
Running git add path/to/file
or git add .
makes git start tracking these files. Then just run git stash
and it might do the magic.
Upvotes: 2