Despite all descriptions, git pull --rebase
works differently than git fetch/git rebase [branch]
. git pull --rebase
is described as an alias for the fetch
+rebase
command, but I'm trying to find out how else they differ?
In another post, I was given git pull --rebase
as a solution to a rebase problem in which git wasn't properly handling commits which have changed hash values due to merge conflict resolution on an upstream feature branch.
Until now, we've been using a combination of git fetch upstream
and git rebase upstream/a-feature-branch
.
However, when done this way, it acted like any commits that no longer match the hashes on the upstream branch were new work. It tried to re-apply them and caused merge conflicts:
$ git fetch upstream
-- no results, already fetched this morning
$ git rebase upstream/a-feature-branch
First, rewinding head to replay your work on top of it...
Applying: D-06437 (note: this commit already exists, but a merge conflict upstream has changed its hash)
Using index info to reconstruct a base tree...
...
Falling back to patching base and 3-way merge...
Auto-merging (file)
CONFLICT (content): Merge conflict in (file)
Failed to merge in the changes.
Patch failed at 0001 D-06437
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
imac: projectName ((c1452be...)|REBASE) $
However, running a pull instead achieves what we want:
$ git pull --rebase upstream a-branch-name
* branch a-branch-name -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: B-07241
This solution doesn't cause any conflicts and has properly updated the history with the modified commit/hashes that upstream has.
Update #1:
git pull --rebase upstream feature-branch-name
equates to:
git-rebase --onto c1452be62cf271a25d3d74cc63cd67eca51a127d 634b622870a1016e717067281c7739b1fe08e08d
Here are the three most recent commits on the developers work branch:
92b2194 Rick B-07241
634b622 Sue Merge pull request #254 from dboyle/B-07290
bc76e5b Bob [B-07290] Order Parts Ship To/Comments
And the most recent commit on the "new" feature branch:
c1452be Sue [B-07290] Order Parts Ship To/Comments
Note: The "merge" commit has been lost and the "Order Parts" commit now shows as being done by Sue, not Bob. I'm trying to confirm, but either someone cherry-picked the commit, or somehow ran a rebase in a way that discarded the merge commits.
Here are several variables that git-rebase.sh
is using during each. The only difference is the onto:
"git-rebase" Variables during `git pull --rebase upstream feature-branch-name`
orig_head = 92b2194e3adc29eb3fadd93ddded0ed34513d587
onto_name = c1452be62cf271a25d3d74cc63cd67eca51a127d
onto = c1452be62cf271a25d3d74cc63cd67eca51a127d
mb = 438cc917c6f517913c9531e0a38f308d3aa13f0b
revisions = 634b622870a1016e717067281c7739b1fe08e08d..92b2194e3adc29eb3fadd93ddded0ed34513d587
"git-rebase" Variables during `git rebase upstream/feature-branch-name`
orig_head = 92b2194e3adc29eb3fadd93ddded0ed34513d587
onto_name = upstream/PartsInterface_E-01960
onto = c1452be62cf271a25d3d74cc63cd67eca51a127d
mb = 438cc917c6f517913c9531e0a38f308d3aa13f0b
revisions = c1452be62cf271a25d3d74cc63cd67eca51a127d..92b2194e3adc29eb3fadd93ddded0ed34513d587
The revisions calculated by "git rebase" are different than git pull.
Note: 634b6228
is a merge commit that only exists on the local branch, it no longer exists upstream.