How do I discard unstaged changes in Git?
Ask Question
up vote
2939
down vote
favorite
982
How do I discard changes in my working copy that are not in the index?
git
share | improve this question
edited Oct 30 ’16 at 14:53
Peter Mortensen
10.9k 15 75 109
asked Sep 9 ’08 at 19:33
Readonly
97.2k 86 178 193
See also stackoverflow.com/questions/22620393/…
– Cees Timmerman
Feb 4 ’16 at 17:11
git-clean only removes untracked files from the working tree git-scm.com/docs/git-clean
– Gboyega
Sep 15 ’16 at 12:29
3
To clarify Asenar’s comment above, git-clean -df can be dangerous. It will delete local untracked files (e.g. covered by a .gitignore) Read all below carefully and consider git checkout . instead
– jacanterbury
Oct 7 ’16 at 8:05
2
‘git clean -df ‘ Be warned! I tried that and lost key folders that are unable to be restored… Ouch!
– Gabe Karkanis
Oct 27 ’16 at 21:01
Greg Hewgill’s is currently the accepted answer, but Tobi’s is better.
– cp.engr
Mar 8 at 15:48
add a comment
28 Answers
active
oldest
votes
up vote
1663
down vote
accepted
Another quicker way is:
git stash save –keep-index
After that, you can drop that stash with a git stash drop command if you like.