Reputation: 1812
This is probably a simple (but irritating) question. How do you remove all changes remove changes since last commit? I botched a patch, and I want to go back to how things were at my last commit.
I have tried:
git reset --hard master
and
git checkout master
but neither rid my folders of the files hat I have added / changed (they are still listed as untracked files.)
Upvotes: 3
Views: 4671
Reputation: 555
A little late to this one, but seeing that on 2017/09/26 this was still indexed as third using the google search engine here is my response. I found what worked for me via this stack exchange discussion: git undo all uncommitted or unsaved changes
Basically if you have not used git add yet then use:
git checkout .
To unstage files staged with git add use:
git reset
Upvotes: 0
Reputation: 169018
Untracked files are just that, untracked. Git doesn't know or care about them. git reset --hard
will only revert tracked files to the state they were in at the most recent (or named) commit.
You can use git clean
to remove untracked files and directories from your working tree. Be careful you don't accidentally delete any hard work!
The "silver bullet" that will restore a repository back to the state it was at as of the most recent commit, as if you had just cloned it (this will even remove all user files that are "ignored" by the repository!) would be this: git reset --hard && git clean -fdx
. (If you omit the x
flag then it will only remove untracked files that are not ignored, which might include build products, for example.)
Upvotes: 5
Reputation: 286
I wish I could just comment on this, but check this out: How to undo last commit(s) in Git?
and here: http://git-scm.com/docs/git-reset
Upvotes: 0