Reputation: 3547
What is the command to get a list of commits that are required to get from commit A to B and in reverse? This would actually be the graph difference between the commit histories of two commits.
Upvotes: 1
Views: 74
Reputation: 489688
git rev-list
can answer these three different, commonly-useful graph-difference questions:
B
but not from A
: A..B
(or B ^A
or B --not A
)A
but not from B
: B..A
(or similar alternatives)A
or B
that are not on their common ancestors: A...B
(doesn't matter which order you specify A and B here).Consider this graph fragment:
-1-2-4-5-A
\
3-B
In this case there's no way to go forward from either A
to B
or vice versa, but you can get the last three commits along the top (4-5-A), or the two along the bottom (3-B), with B..A
and A..B
respectively. You can get all five of these with A...B
. Using both A..B
and B..A
you can figure out what to remove from A (A itself, then 5, then 4) and then add (3 and B
itself), to get "from A to B".
Commits are, as the documentation says, listed "in reverse chronological order by default", but this is also controllable. You probably want --topo-order
and sometimes --reverse
.
However, in the presence of complex topology, a simple sequence like the above ("remove this, add that") is not sufficient. For instance:
...-x-o-o-o-o-o-B
\ / /
A-o-o-o
All of the o
nodes may be important to get "from A
to B
", but now, no purely linear traversal (commit X before commit Y, then commit Z) can reconstruct the full graph: you need more information (e.g., listing the parents associated with each commit). git rev-list
can do all of this; read and study the man page examples closely.
Upvotes: 1