0

Maybe I have the wrong approach to Git-Flow...

I use Bitbucket (git) with GitFlow workflow.

I would like to know if it's possible to completely remove source changes of a feature branch after a merging with develop branch even after other branch features were merged

Edit: I try to explain better. I don't want to delete a feature branch, I want to remove all the changes brought by the feature branch.

I think that I can revert if my feature-branch is the last operation. But if: - I've done the merge of my feature-branch on develop-branch - other features have merged on develop-branch

and only after this operation I need to remove my first feature without lost any other features, it's possible?

Thanks, Ruggero

1 Answers1

1

In interpret your question so that you want to undo the merge of your featurebranch into develop.

This should be possible using

git checkout develop
git revert mergecommit -m 1

Where mergecommit is the hash of the actuall merge commit (as shown by git log).

There is a caveat in git help revert:

   -m parent-number, --mainline parent-number
       Usually you cannot revert a merge because you do not know which side of the merge should be considered the
       mainline. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse
       the change relative to the specified parent.

       Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a
       result, later merges will only bring in tree changes introduced by commits that are not ancestors of the
       previously reverted merge. This may or may not be what you want.

So:

  • You need to find out which side of the merge you want to pick. git log, look for the line Merge: aaaaa bbbbb, and pick -m 1 or -m 2 accordingly.
  • You may want to provide the -n option to avoid the automatic commit, just to avoid a bit of hassle in case it goes wrong.
AnoE
  • 8,048
  • 1
  • 21
  • 36
  • Thanks! I edited my question... It's possible to remove even if other features have merged after my? Thanks – Ruggero Scarano Aug 05 '16 at 12:54
  • Yes, it is possible. It will not edit the history, but you will create a new commit which practically undoes the change. Of course, you might or might not have lots of conflicts, if you are unlucky. – AnoE Aug 05 '16 at 14:34
  • What do you do if any fixes were required for the feature after the commit of the feature branch? – Tom Anderson Nov 17 '21 at 01:43
  • 1
    @TomAnderson, spontaneously, I'd say `git cherry-pick`'ing the relevant later commits might be worth a try. – AnoE Nov 17 '21 at 07:43