0

I have created a feature branch(Feature1) and worked on it. Pull request merged to remote master branch (with no fast forward option- azure devops). After that some other checkins are done on master branch from other developers.

I have created another feature branch (Feature2) and worked on it. Again pull request merged to master branch.

Now I want to revert Feature1 and Feature2 branch changes from master. I did not delete Feature1 and Feature2 branches.

Feature1 and Feature2 branches are supposed to merge into another branch instead of master.

Now how should I remove Feature 1 and Feature2 changes from master without touching other developers checkins?

James Z
  • 12,209
  • 10
  • 24
  • 44
PSR
  • 875
  • 2
  • 13
  • 37
  • https://git-scm.com/docs/git-revert – Thomas__ Mar 02 '20 at 14:51
  • Read this answer, it will light your day: https://stackoverflow.com/questions/34519665/how-can-i-move-head-back-to-a-previous-location-detached-head-undo-commits/34519716#34519716 – CodeWizard Mar 02 '20 at 14:54

1 Answers1

1

Since it is master branch that you want to revert the commits from, your best option is git revert. If you try to completely remove the commits from history of master through an interactive rebase, for example, the commit IDs that follow the removed commits will change. Remember, you do not want to change the commit IDs in master because other developers could be working on feature branches having those commit IDs and they can land in to trouble with merge conflicts when they later merge to master.

You could find the feature branch commits and revert them like below on a new feature branch created from master and then give pull request to master.

git revert feature1Commit1..feature1Commitn
git revert feature2Commit1..feature2Commitm

This actually creates new commits which reverts your changes. So, your feature1 and feature2 commit IDs stay in master, but the changes you made will actually be reverted in the new commit IDs created.

Rinshad
  • 116
  • 4