-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?

0

1 Answer 1

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
3
  • 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? Commented Mar 25, 2014 at 3:13
  • Ah, you mean versus your remote? Use git push -f origin master to update your remote.
    – acjay
    Commented Mar 25, 2014 at 3: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 reverted – not erased. See linked questions for detail.
    – johnsyweb
    Commented Mar 25, 2014 at 3:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.