3

I need to return to the last commit state. I've done a Git Reset Hard, but when I make new changes to the code and try to commit, I see that all the files tahs I don't wan't to have in the repo are there.

How can I make a Reset that also delete the not commited files?

Best Regards,

André
  • 23,203
  • 42
  • 115
  • 174
  • try this http://stackoverflow.com/questions/8903953/git-revert-last-commit-and-remove-it-from-history – Koenyn Feb 27 '13 at 18:36

4 Answers4

4

git reset --hard will put you back to the last commit, losing any changes you have made to files that have already been committed.

git clean -xdf will then remove any files and directories that you have created but have not yet committed to git.

Running both of these should put you back into a clean state.

adrianbanks
  • 79,167
  • 22
  • 173
  • 203
2

git checkout -- . (there is a dot at the end of command) will revert all changes in working directory.

poke
  • 339,995
  • 66
  • 523
  • 574
0

If you want to remove files that aren't being tracked then try the following:

git add .
git reset --hard

I think there's a more appropriate way, but can't think of it right now. Will post it if I do.

Trevor Norris
  • 19,029
  • 3
  • 25
  • 26
0

OK, you have:

  • git clean -x: removes files not under version control, including ignored files
  • git reset --hard: goes to the mentioned commmit, checks out the files just as they are recorded in it

Using both should give you what you want, if not, it's a bug.

vonbrand
  • 10,868
  • 8
  • 30
  • 50