Find commits in a reverted merge
I did a merge of a unfinished branch to master. I did a revert merge to reverse the code changes.
Now the problem is I cannot merge this particular branch again to master. So what I plan to do now is to create a new dummy branch and cherry pick the lost commits and put it in the new branch and merge the above branch to the newly created branch and resume development from the newly created branch. This would work.
My question is is there a neat way of achieving the same in git?
I don’t want to do a revert of revert.
2 Solutions collect form web for “Find commits in a reverted merge”
Your second merge is not working because git understands that it is already merged.
What you say about the cherry pick is an option. I propose you to use rebasing instead of cherry pick.
git checkout dev // do your staff git add . git commit -m "Finish the work" git rebase master
With this, you regenerate all the history of your dev branch again from the last position of master branch. And git will now allow you to merge it.
Except the cherry-picking, which you probably should do, there is a tricky way to make git think the branch still not merged – replace the merge commit with identical non-merge commit.
git replace --edit <merge commit>
In the editor open the will be text like
tree AAAAA parent BBBB parent CCCCC author ...
Then remove the second “parent ” line (with CCCC), save, exit. Now the merge commit will be seen to git as simple commit, and the branch can be merged again.
The replacement can be removed after second merge.