3

I host my files on bitbucket and normally commit changes every now and then.

Since my last commit, I have made some mistakes in my code.

(These mistakes have been saved in their respective local files and I haven't added it to the local git repo just yet using git add.)

I would like to revert back to my last commit with the working code. I am currently working on a branch off the master.

What command should I use for this?

numaroth
  • 1,295
  • 4
  • 25
  • 36
Manuel da Costa
  • 107
  • 1
  • 2
  • 7
  • Some previous threads: http://stackoverflow.com/questions/4114095/git-revert-to-previous-commit-how http://stackoverflow.com/questions/5004237/git-revert-to-previous-commit-status http://stackoverflow.com/questions/4965639/rollback-to-last-git-commit ... – eis Jan 09 '13 at 22:05
  • @eis nope, the talk is about reverting not yet commited changes. – om-nom-nom Jan 09 '13 at 22:33
  • 1
    possible duplicate of [How to selectively revert or checkout changes in git?](http://stackoverflow.com/questions/771897/how-to-selectively-revert-or-checkout-changes-in-git) – om-nom-nom Jan 09 '13 at 22:36
  • @om-nom-nom so are those links? – eis Jan 10 '13 at 08:32
  • possible duplicate of [How do you discard unstaged changes in git?](http://stackoverflow.com/questions/52704/how-do-you-discard-unstaged-changes-in-git) – CharlesB Feb 18 '13 at 06:28

2 Answers2

1

For a file: git checkout -- filename also git checkout -- directory/ will do this for the entire directory and of course git checkout -- . for the entire repository.

Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72
1

git reset --hard will revert all files to HEAD. I prefer this to git checkout -- . but that's just a matter of preference.

aragaer
  • 17,238
  • 6
  • 47
  • 49