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é
  • 24,706
  • 43
  • 121
  • 178
  • 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

5

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
  • 81,306
  • 22
  • 176
  • 206
2

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

poke
  • 369,085
  • 72
  • 557
  • 602
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
  • 20,499
  • 4
  • 26
  • 28
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
  • 11,412
  • 8
  • 32
  • 52