-2

I've committed some changes to local git repo with command git commit -m "Change X"

Question: Is it possible to revert/remove this change from local git and my working directory?

I know I can use git commit ammend to rewrite this commit, but I want to delete it, I dont want to put it to remote repo.

Pawel
  • 27
  • 9

1 Answers1

1

Try like this,

Undo your commit, files and your index.

git reset --hard HEAD~1

Undo your commit but leave your files and your index.

git reset --soft HEAD~1
Adem Öztaş
  • 20,457
  • 4
  • 34
  • 42
  • OK it works:) ... I tried git reset --hard HEAD, why it was wrong:)? – Pawel Oct 16 '14 at 12:40
  • The last three commits (HEAD, HEAD^, and HEAD~2) were bad and you do not want to ever see them again. Do not do this if you have already given these commits to somebody else. --> http://git-scm.com/docs/git-reset – Adem Öztaş Oct 16 '14 at 12:43
  • Is is possible to remove this change from local repo and ADDITIONALLY bring all these changes back to working directory,in order to make working directory like before last "git add .." ? – Pawel Oct 16 '14 at 12:48
  • Try without the `--hard` or with `--soft` instead. But have a look at this answer: http://stackoverflow.com/a/6866485/1112326, it explains everything pretty well :) – Dettorer Oct 16 '14 at 12:53
  • @Pawel Of course it is possible. Like this ``git reset --soft HEAD~1`` – Adem Öztaş Oct 16 '14 at 13:09
  • @Dotterer Thanks, it is wery good link:)! – Pawel Oct 16 '14 at 13:12