-2

I needed to rollback my branch a few commits back, as newer commits introduced bugs.

I tried to solve my problem with help of stackoverflow and just googling for git tutorials, but I feel I made it worse. Right now my git branches look like this:

enter image description here

The blue line is called Development, the pink - master.

My actions were to checkout a new branch from my selected commit, checkout to master to get rid of detached head and merge the two branches. But merging brought back the bugs from the "bad" commit.

How can I just rollback to the first bullet point in this tree and erase the buggy commits from existence?

Creative Magic
  • 3,143
  • 3
  • 28
  • 47

1 Answers1

3

There are many ways to do this. If I were on master, the way I'd do it is as follows:

  1. git branch safety to keep a branch at the old HEAD
  2. git reset --hard abc123 to move master back to the old commit, assuming that commit was abc123
  3. git branch -D safety to discard the safety branch, if desired
acjay
  • 34,571
  • 6
  • 57
  • 100
  • I got back to the commit I wanted to be at, now I'm 8 commits behind. How can I remove other (newer) commits so I don't pull the buggy content again? – Creative Magic Mar 25 '14 at 03:13
  • Ah, you mean versus your remote? Use `git push -f origin master` to update your remote. – acjay Mar 25 '14 at 03:18
  • 2
    Woah! `git push -f origin master` is a really bad idea. That branch is public and others could have pulled it. This command will rewrite others' history. These commits, when published, should be `revert`ed – not erased. See linked questions for detail. – johnsyweb Mar 25 '14 at 03:45