I used my local branch feature
to create a PR for a github repo (I don't have write access to it). Later I decided I want to separate its last commit into a standalone PR, so I moved feature
one commit back:
git checkout feature
git branch feature2
git reset --hard @~
git push -f
The first PR is merged upstream, so now I want to create the second PR:
git checkout master
git pull upstream master
git push origin
git checkout feature2
git rebase master
Unfortunately, it turns out that git
lacks the information that feature
was merged into master
. Therfore, it doesn't realize that the nearest common base of feature2
and master
is very close: it's just feature
. Instead, rebase
goes back all the way to common base of feature
and master
as if they were never merged. As a result, git rebase master
becomes unnecessarily messy.
Why did Github
lose the information that feature
was merged into master
through an upstream PR? Is there any way to provide Github
with that information?
In the end, I had to resort to:
git checkout master
git checkout -b feature2_new
git cherry-pick feature2
Luckily I only needed to take care of a single commit. And even with a single commit, I think that a merge with the true base (if git knew about it) would be better than the cherry-pick
because git
would be able to use its knowledge of history to resolve more conflicts automatically.
Note that if I were to merge feature
into master
locally instead of doing a github PR, no information would have been lost. Of course, then my master
would not be in sync with the upstream repo, so it would be pointless.
upstream
remote has proper URL set? Check withgit remote -v
– Tinderboxmaster
. Even though that commit corresponds to a (squashed) version of my local commits infeature
, there's no history linking them. – Demodulationmaster
, the commit that was created by the PR has only one parent. – Demodulation