Merging a branch with a reverted change

Here is the situation.

I accidentally committed to master branch which I actually wanted to commit to branch X.
Then I merge master to X then git revert the changes on master.

But eventually this X will be merged to master but then It won’t merge this reverted change.

What is the most proper way to fix this?

>Solution :

Rewrite the history of the branch so that to git, it is like that is work that has never been merged into the branch. Suppose that the branch is 2 commits:

git checkout some-branch~2 # we start from the point where that work was started
git cherry-pick HEAD..some-branch
# that will create 2 new commits with the same stuff as the original 2
# but this is something that has never been merged
git branch something

This branch can be merged into master

Leave a Reply