If there are two git commits (or refs) A and B, and if A is known to be an ancestor of B in the history, is there an easy way to compute an expression that shows how A can be reached, starting from B (going backwards through the ancestry path)?
In other words, how to generate a description of A, as a relative path that starts out from B - with results like these:
A = B~1
- i.e. A is the direct parent of B (first parent, if B is a merge)
A = B^2
- i.e. A is the 2nd parent of (merge-commit) B
A = B~22^2~3
- i.e. A is the 3rd ("first") ancestor of the 2nd parent of a merge that is the 22nd ("first") ancestor of B
In practice, this might be useful as an indicator of how far two commits are apart in the history graph - sort of a condensed form of what --ancestry-path
can show in git log
(but also with fewer information).
Can something like this be generated using git built-in tooling...?
I realize that there can well be multiple valid paths, going from B back to A - so any resulting expression won't necessarily be unique.