Reading the git rebase
and git merge-base
man documentation:
After working on the topic branch created with git checkout -b topic origin/master, the history of remote-tracking branch origin/master may have been rewound and rebuilt, leading to a history of this shape:
o---B1 / ---o---o---B2--o---o---o---B (origin/master) \ B3 \ Derived (topic)
where origin/master used to point at commits B3, B2, B1 and now it points at B, and your topic branch was started on top of it back when origin/master was at B3. This mode uses the reflog of origin/master to find B3 as the fork point, so that the topic can be rebased on top of the updated origin/master by:
$ fork_point=$(git merge-base --fork-point origin/master topic) $ git rebase --onto origin/master $fork_point topic
$fork_point
will ( if I understand it correctly ) be the commit object B3
, and, thus the commits B3..topic
will be rebased onto to origin/master
branch.
Q1 Why is it useful to omit the B3
commit? The commits of the topic
branch are built on top of the B3
commit, so omitting it would mean that its modifications would then be missing in the story of the origin/master
branch. Rebasing the B3
commit and the topic
branch would lead to a cleaner history, wouldn't it?
Q2 Can someone link / briefly describe practical use cases of the --fork-point
option in the git workflow?