I need to identify differences between two branches in a baseless manner. The branches diverge often and only need to be the same when I merge them (once a sprint). They appear to drift even after merging when someone makes a hotfix change to the target branch and it inadvertently doesn't bring some other changes. Either way, git diff
shows the branches differ and git merge
says there is nothing to merge.
I can use git diff
to identify what changes exist, and I have a script that performs a baseless merge using git merge --allow-unrelated-histories
. What I'm working on now is backing up to the last merge so I can compare just the merge to the parent.
Consider this git graph:
...-A-B---C---D---E---F---G---H
\ ↑
... \ main
\ \
I-J---K---L---M---N---O
\ \ / / ↑
\ f / release
\ /
--d--
I know the main
and release
branches. Given release
is O
I'd like to determine that K
is its last merge from main
and that commit B
was that parent. How do I travese O
s history and determine K
was the most recent merge and B
is its parent?
Determining merges
git rev-list --min-parents=2 <O>
would list out all parents and lead me to K
though I would need to rule out N
and M
before that.
Determining parents
I do not know how to do this (given K
, determine either B
or B
& J
).
Determine parent's descendents
I do not know how to do this (given B
, determine that H
is a descendent; and given J
, determine that H
is NOT a descendent)
Traverse process
If I use git rev-list
and similar I'll need to loop over each commit hash returned (to test for parents and parents's descendents). Not the end of the world but if git could do the work for me that would be less error prone.
Determine differences
git diff --name-only <B> <K>
would show me file differences between B
and K
Perform baseless merge
Meh. A multi-step script involving checkout --orphan
and merge --allow-unrelated-histories
. I'll leave that out but I have a solution for that.