Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I "back out" a feature branch merge in Git?

Tags:

git

I am relatively new to Git and I want to know if this is correct to do and if there are other ways to remove a feature branch which is merged to master branch. Let me explain with a example:

Let us assume we are working on three tickets (bugs/enhancements) and there are three feature branches one for each ticket each branched off from the Tag v2.0.21. After the development work is done on each ticket, and after sufficient testing, we merge it to the master branch and label this branch as say v2.0.22 and release it to production.

Right after the production release, let us say we figured out one of the ticket (Ticket2) is failing and should be removed. This is what I've in mind and I wanted to know if this is a good approach to remove the commits associated with Ticket2.

Like say,

  1. Create a new branch from v2.0.21
  2. Merge Ticket1 (Branch1) and Ticket3 (Branch3) on this new branch
  3. Force push new branch to master.
  4. Tag master as V2.0.23
  5. Release code from v2.0.23 to production.

I hope someone can help me validate this approach and suggest better ways to remove a feature branch that is already merged to master. Thanks!

like image 972
Scarface Avatar asked May 02 '12 00:05

Scarface


1 Answers

If your merges create a "merge commit", which is often a good idea for this very reason, then you can reverse the changes from a specific feature branch by using the git revert command with the commit ID of the merge commit for that branch.

The Git documentation includes a detailed note on how to revert a faulty merge which has more information that you may find useful.

like image 198
Greg Hewgill Avatar answered Nov 11 '22 14:11

Greg Hewgill