0

How can I remove a commit from master branch, which was merged from my feature branch?
On top of that, both my local and remote branch is deleted.

I only have a master branch which has all the commits pushed from my feature branch.

---o---o        origin/feature !! This feature branch is both locally and remotely deleted !!
           \
----o----●------>      origin/master

Is it possible to remove ● from the above picture, when I have already removed both my local and remote feature branch?

FluffyCat
  • 55
  • 2
  • 9

1 Answers1

1

● is the merge commit from bring your branch in to master. To get rid of this commit can be complicated depending on a couple of factors. You will need to rebase the commits from origin/feature and replace them for ● on origin/master. One thing with this is that you are changing history and if there are others pulling changes from origin this will cause a lot of problems as you will need to force push the changes to origin (not recommended unless you are the only one accessing the remote branch).

This can also be difficult depending on the number of commits after ●.

If you want to do this you will need to find the commit where origin/feature diverted from origin/master. Since the branch is deleted you will need to look through the graph. When you find this commit, note the hash. And run git rebase -i <sha of the diverging commit. This should give you a list of all the commits, that happened since then. You should be able to rearrange them which would remove your problem commit.

Doing these steps can cause alot of repetitive fixing of conflicts when git is reapplying the commits from origin/feature. It also will cause them to change, you will be the committer of these changes and iirc will also change the date of the commit.

I wouldn't recommend doing this for this commit. But to prevent it from happening, when you want to bring in a feature branch in the future. Do git rebase -i <feature branch>on master instead of git merge. This will prevent the new commit from being created.

Schleis
  • 41,516
  • 7
  • 68
  • 87