gitgithubreset

How to rollback the two previous commits?


Consider this scenario:

  1. Developer A does a commit: #n
  2. Dev. B does commit #n+1
  3. Dev. A does commit #n+2
  4. and commit #n+3

and then discovers that in his commit #n+2 he introduced a defect.

How can dev. A rollback his last 2 commits and continue developing on commit #n+1?

Tried git reset --hard HEAD~2*, but it's coming back to dev A's commit #n.


Solution

  • It should come back to the n+1 commit. You probably have a merge commit in there as well. You can also do a git reset --hard <sha1_of_where_you_want_to_be>

    WARNING!! --hard means that any uncommitted changes you currently have will be thrown away permanently.