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?
Asked
Active
Viewed 112 times
1

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 Answers
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
-
1If you commited 6 times, not pushed and want to trash it away, this is a good way. – Richard Dally Jul 29 '15 at 12:08
-
@LeFlou - Ok.. I could try that.. There are no differences between the 6 commits – TheLostMind Jul 29 '15 at 12:09
-
-
@LeFlou - I meant to say that I don't need the files that I changed in the last 6 commits – TheLostMind Jul 29 '15 at 12:13
-
@TheLostMind, Take a look at [git reset documentation](http://git-scm.com/docs/git-reset) – Richard Dally Jul 29 '15 at 12:14
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
-
@TheLostMind: and have you used "reword" option during interactive rebase? see https://robots.thoughtbot.com/git-interactive-rebase-squash-amend-rewriting-history – quetzalcoatl Jul 29 '15 at 12:09
-