kaizenCoder kaizenCoder - 1 year ago 159
Git Question

How to perform a git rollback via a Pull Request?

We strictly use PRs to introduce changes to our

branch (as you would). My assumption was that a rollback would mean creating a
branch before merging the
topic branch and if we require, we can rollback via the
PR. However this doesn't work as I thought.

Create rollback branch:

git checkout 6af89ed -b rollback-prod

Merge Feature branch:

# production branch
git merge new-feature


# production branch
git merge rollback-prod
Already up-to-date.

As you can see (correct me if I'm wrong) because the commit already exists in the
branch it relays
Already up-to-date

The issue I face is, this rollback needs to happen via our GUI git tool (bitbucket). So manual command fixes is not really an option.

Is there recommended way to rollback to a commit via a PR?


I'd like to make it clear that the
needs to be created in advance so that Ops do not have to touch the command-line in the event of a rollback..assuming this is possible, perhaps not.

Answer Source

There are two ways to effectively "rollback" a commit in Git. One is to perform an interactive rebase in which you remove one or more commits, and the other is to do a git revert. However, because you want to effect the rollback via a pull request, the only option is to do a git revert. So you can try the following:

git checkout production
git checkout -b rollback-prod      # create rollback branch from production
git revert 6af89ed^..HEAD          # add revert commit to this branch
git push origin rollback-prod      # push this branch to Bitbucket

Now, you can create a pull request in Bitbucket for the rollback-prod branch. Once it is completed, the 6af89ed commit will be effectively reverted.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download