I have this scenario: There are 2 branches, 'develop' and 'feature-branch'. This two branches have been growing over time each one independently. Now, 16 of November of last year, a merge was done from 'feature-branch' to 'develop'. This merge should not have been done so it was reverted on 19 of November. The problem: now the files in develop are newer, so when doing a merge from 'develop' to the branch to integrate both, git keeps the files in develop. This is a problem because there is code on the branch which is necessary, and since it doesn't create conflicts, I'm not able to integrate them. I would need to manually check every file and check the logic, which is not ideal. Is there any way of fixing this?
Asked
Active
Viewed 695 times
1
-
1Merging is not about which files are *newer*. Merging, in Git, is about *combining work*. This requires figuring out what "work" was done, which in turn requires locating the *merge base* commit, then running two `git diff` commands. See, for instance, [my answer here](https://stackoverflow.com/a/56894290/1256452). – torek Apr 22 '22 at 07:30
-
1In general, if some merge was done, then reverted, and now needs to be re-performed, the usual approach is to revert the reversion. In some cases this is not suitable though; in those cases, it makes sense to copy some (but not all) of the commits whose *work* was reverted to new-and-improved commits in one of the two commit-streams that will be merged, or to the result of merging those two commits-streams. – torek Apr 22 '22 at 07:31
1 Answers
2
- Checkout a new local branch called 'prepare-develop-for-merge-into-feature-branch' based on the merge-revert commit of 'develop'.
git checkout -b prepare-develop-for-merge-into-feature-branch <commit-id-of-merge-revert>
- Create a commit that reverts the merge-revert
git revert HEAD
- Checkout 'feature-branch'
git checkout feature-branch
- Merge 'prepare-develop-for-merge-into-feature-branch' into
it
git merge prepare-develop-for-merge-into-feature-branch
- Merge actual 'develop' into 'feature-branch'
git merge develop
The result should then look like what you'd expect it to look if that merge-revert never happened.
Note: There are other approaches to solving this (e.g. reverting the merge-revert direclty on top of feature-branch). However, I've chosen this approach, because it should cause git blame
to still point at the original commits (instead of the revert-revert) while also keeping possible merge-conflicts to a minimum.

Jay
- 3,640
- 12
- 17