following situation:
I made some changes in the development branch ( commit f + g ). Unfortunately, there were some changes in the master branch (commit e + d), which are now obsolete and have to be ignored. So, I am searching for a solution to merge the development branch into the master branch and ignore commits e and d.
So far, I had the following thoughts:
Do you have a more beautiful idea than though 3?
I agree with the suggestions in Nikola's answer: the more general solution is you should revert the commits on master
, then merge in develop
. Resetting master
back to before those commits also works well here if your team is willing to do that.
There is another option, which is to merge master
into develop
and ignore the changes brought in by master
. But this should only be considered if certain conditions are met:
master
you can simply revert the merge commits, however, you can only do this if you wish to revert all of the commits brought in by that merge.master
that aren't in develop
. (There are workarounds if this isn't true, but you do need all of the commits you wish to ignore to be grouped together.)If you wish to go this route, the commands would be:
git switch develop
git pull --ff-only # Update your copy of develop and if it errors you're out of sync!
git merge origin/master --strategy=ours # ignore everything new on master
# now you can merge develop into master
Note --strategy=ours
is sometimes written as -s ours
and this merges in commits without their corresponding changes. I would consider this abnormal, and if you do it I suggest using a detailed note in the merge commit message explaining why you did this.
If you have just a few commits that need to be reverted I would recommend just reverting them all, as it's cleaner and easier to historically follow from a reader's perspective.