When you have upstream that is different from origin, how you can count difference between local and upstream?
git rev-list --count upstream/master..master
returns 0 despite the fact that upstream is few commits ahead of local master branch.
When you have upstream that is different from origin, how you can count difference between local and upstream?
git rev-list --count upstream/master..master
returns 0 despite the fact that upstream is few commits ahead of local master branch.
Consider using the three-dot notation and the --left-right
flag:
git rev-list --left-right --count upstream/master...master
As described in the gitrevisions documentation, the three-dot notation A...B
produces a symmetric difference of the sets of commits reachable from the two identifiers or hash IDs A
and B
. (For much more on reachability, see Think Like (a) Git.)
Normally this would just be:
upstream/master
that aren't on master
, plusmaster
that aren't on upstream/master
which would just be a sum. But adding --left-right
tells Git to split the sets into two. Without --count
, you get a listing annotated with <
and >
markers to tell you which commit hash goes with which identifier. With --count
, you get two counts. In this case, if upstream/master
is strictly ahead of master
, the first count will be nonzero and the second count will be zero. For instance, if upstream/master
is 2 ahead, the output is 2 0
.
This works if you reverse the names, too; it's just that now the counts are swapped around. For the above case, you'd now get 0 2
.
Pick whichever order you like and get both counts, or use the two-dot notation to get just one count. The one count you get, with A..B
, is the count of commits reachable from B
but not reachable from A
. If upstream/master
is "ahead" and you want that count, you need master..upstream/master
when using the two-dot method.
The number of commits upstream is ahead of master:
git rev-list --count master..upstream/master
master..upstream/master
is the range of commits that are in upstream but not in master. It's equivalent to upstream/master ^master
.
See What are the differences between double-dot ".." and triple-dot "..." in Git commit ranges? for more information.