Several weeks ago I pushed something to master that ended up needing to be reverted.
Now I've made the changes and am ready to push them to master again. My normal workflow is to checkout master, pull the latest version from origin, checkout the feature branch, merge in the new changes from master, and then make a PR to master.
When I try to merge in the changes from master, the revert commit is deleting lots of stuff in my feature branch that I need to keep.
What is the best way to handle this?
So what you are saying is that on origin master has been reverted, but you need to add the reverted changes back in? Like
In this case merging master into your feature branch means the revert commit marked with
*
in the above graph will be added to your changes, so that's why stuff is removed from your branch.So what you can do is to create a new branch starting at the revert commit, then revert the revert again (un-revert<), merge this branch to your feature branch, and then merge master to your branch.
That way, when merging master, the revert is already in your feature branch, but cancelled out by the unrevert commit, so the revert will not be added to your changes.
You can see that now the revert commit is already on your feature branch, so merging master may add some other commit marked with
*
above, but not the revert.Generally in the situation that something has been reverted on master, and you want to work on it and push it again, you should start at the revert commit and unrevert first (git revert revert-commit).