Reputation: 21453
Sorry for the confusing title, but I couldn't come up with a better one.
Here's my problem. I have 2 branches, develop
and feature
. I followed this process:
feature
feature
into develop
develop
.Now I want to merge the changes I made directly to develop
back into feature
. The problem is that when I do that, it blows away all the changes I had previously made in feature
. I assume this happens because the revert in step 3 is more recent than any code changes in feature
, so it applies that revert over the changes.
Is it possible to do what I'm trying to do? The only thing I could think of is to revert the revert in develop
, then merge, then revert the revert of the revert. That seems kind of cumbersome.
Upvotes: 2
Views: 344
Reputation: 521123
I think you can rectify the situation in two steps:
1) Do an interactive rebase of develop
and remove the revert commit, i.e.
git rebase -i HEAD~6 # or however far back is the merge commit
Delete the line containing the revert commit and complete the rebase. At this point, develop
now has the original merge commit, but no revert.
2) Do a rebase on develop
, specifying the hash of the commit from which both develop
and feature
originated. By default, rebase will ignore the merge commit entirely, thereby removing it:
git checkout feature
git rebase <SHA-1>
where <SHA-1>
here is from the commit whence feature
branched off from develop
.
After these two steps, your develop
branch will have neither merge commit nor revert commit, and you should be safe merging it into feature
.
I strongly recommend reading the answer given by @torek in this question:
Accidentally merged in wrong branch to mine. Is there a way to remove these unwanted files?
Upvotes: 2
Reputation: 27295
Normally you make a feature branch and you work on that branch to complete your feature. Then you merge your feature to the develop branch and after some time the develop state goes live.
In your case if you have changes on the develop branch i would prefer a rebase on your feature branch. Then you get all changes and your feature branch is rewritten to the last commit of your dev branch.
Atlassian has a good tutorial how you can work with feature branches.
https://www.atlassian.com/git/tutorials/comparing-workflows#feature-branch-workflow
Upvotes: 1