You can try with the --all --branches
log parameters:
git log -1 --all --branches -- yourFile
That will give you the most recent commit across all branches.
To limit that to only two branches, the --branches
takes a shell glob pattern.
But that does not support an "or" in the pattern expression though. You might have to display the branch and grep for the ones you want.
As torek mentions in the comments, a revision range branch1...branch2 is also a simpler alternative.
That would be using the three dots notation, to target the set of commits that are reachable from either one of branch1
(left side) or branch2
(right side) but not from both.
So:
git log -1 branch1...branch2 -- yourFile
With Git 2.33 (Q3 2021), the notion of "revision range" is clarified:
See commit f302c1e (18 May 2021) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit b009fd4, 10 Jun 2021)
revisions(7)
: clarify that most commands take a single revision range
Sometimes new people are confused by how a revision "range" works, in that it is not a random collection of commits but a set of commits that are all connected to each other, and most Git commands work on a single such "range".
Give an example to clarify it.
revisions
now includes in its man page:
There are several notations to specify a set of connected commits
(called a "revision range"), illustrated below.
revisions
now includes in its man page:
Commands that are specifically designed to take two distinct ranges
(e.g. "git range-diff R1 R2
" to compare two ranges) do exist, but
they are exceptions.
Unless otherwise noted, all "git
" commands
that operate on a set of commits work on a single revision range.
In other words, writing two "two-dot range notation" next to each
other, e.g.
$ git log A..B C..D
does not specify two revision ranges for most commands. Instead
it will name a single connected set of commits, i.e. those that are
reachable from either B or D but are reachable from neither A or C.
In a linear history like this:
---A---B---o---o---C---D
because A
and B
are reachable from C
, the revision range specified
by these two dotted ranges is a single commit D
.