The problem occurs because as far as git is concerned, b
is already in master
(along with more recent changes that happen to undo b
). This interferes not only with the review, but with the actual merge result.
There are a couple techniques commonly used to address this. Sometimes you "revert the revert"; sometimes you copy B
to create a new commit B'
that does the same thing as B
, but isn't topologically "already in master
."
In your case, you want the latter. (The only clean way to "revert the revert" would be on master
, which would again bypass the review. You want the changes from B
reflected on your branch instead.)
So you have
... a -- b -- d <--(your_branch)
\
!b <--(master)
(I've renamed c
from your picture to !b
to better describe what it is - a revert of b
.)
You need some expression that resolves to a
.
This could be the commit hash for a
(or an abbreviated form of the commit hash); if you have that available, I'd just use that.
Or, in this example you could use your_branch~2
because your_branch
has 2 commits after a
(those being b
and d
).
If you're not sure how many commits are on your_branch
, you might be able to use something like $(git merge-base your_branch master)^
(note the ^
at the end). This relies on the fact that b
is the common ancestor of your branch and master, but will fail if there have been any later merges between the two branches.
Anyway, whatever expression you come up with, I'll use a
as a placeholder in the following command. So you'd do a "forced rebase" of your_branch
.
git rebase -f a your_branch
This should give you
d
/
a -- b -- !b <--(master)
\
b' -- d' <--(your_branch)
(I still show the original d
commit in this diagram, but default git output will no longer show it because it's unreachable. After some time, it will be deleted by the garbage collector. b'
is just like b
except it isn't reachable by master
; and d'
is just like d
except its parent is b'
.
This is a history rewrite of your_branch
, so given that you've previously push
ed your_branch
you would now have to force-push it (git push --force-with-lease
). If there's a chance that anyone else has fetch
ed your_branch
- and especially if they might have already based work on it - then you need to communicate with them about what you're doing. (See the git rebase
docs under "Recovering from upstream rebase".) (If this is likely to be a problem, you could avoid this issue by creating a new branch that's never been push
ed, and rebasing that instead of directly rebasing your_branch
.)
Once this is done, you should be able to do your pull request.