0

For example, in local
1st commit: 10am
2nd commit: 11am
3rd commit: 12pm
4th commit: 1pm
After the 4th commit, I found that the code is not working, so, I want to restore to 2nd commit, how to do it?

There are two cases after I restore to 2nd commit:

  1. I found the bugs and I think that 3rd and 4th commit is no longer working, so I would like to delete the 3rd commit and 4th commit, and then commit again for my bug fixing.
  2. I fixed the bugs and since the 3rd and 4th commit code is useful, I would like to have my 5th commit that is combination of my bug fixing at 2nd commit and the 4th commit.

I am new to Git, please help to solve the problem. I am using Eclipse with EGit for my Android project.

Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
jjLin
  • 3,281
  • 8
  • 32
  • 55
  • answer from Kyralessa may help: http://stackoverflow.com/questions/927358/undo-last-git-commit – bryanmac Jan 19 '13 at 04:48
  • possible duplicate of [Revert to previous Git commit](http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit) – Wolfer May 29 '14 at 16:55

1 Answers1

0

There are several options to delete commit 3 and 4

If you have not pushed code anywhere, you can use git reset

git reset --hard HEAD~2

I you have pushed code anywhere

git revert HEAD
git revert HEAD~3 
(actually it is head~2, but now head is incremented by 1 in 1st revert)
and then push
forvaidya
  • 3,041
  • 3
  • 26
  • 33