1

I am new to GIT. I tried committing code to my brach. The commit would work fine but push would fail because I was not adhering to the standard push comments (not the issue here) . Now, I have 6 failed commits. git status says : Your branch is ahead of 'branchX' by 6 commits. How can I undo all my failed commits?

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
  • possible duplicate of [Revert to a previous Git commit](http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit) – Vorsprung Jul 29 '15 at 12:05

2 Answers2

2

git reset command should deal with it.
It will undo the last 6 commits from the head.
Note that you will lose your current changes in this local repository (if any)

$ git reset --hard HEAD~6
Richard Dally
  • 1,432
  • 2
  • 21
  • 38
1

Most probably, git reset --hard <to-what-point>, but please create a local branch first on your HEAD, or you will have a hard time finding your commits afterwards. Once you are sure they are not needed any more, just delete the branch.

Also, please note that if your problem is just in bad commit messages, then git rebase --interactive will let you easily rewrite the commits and correct messages.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107