Listing and counting commits: git rev-list
A quick way is to do what it git statusdoes when there is an upstream. In particular, it git statussimply counts revisions that are in the current branch, which are not in the upstream branch. For example, consider a branch foothat has upstream origin/foo, and suppose you made three local commits, and then used git fetchto bring up one upstream commit:
L - L - L <-- foo
/
... - C - C
\
U <-- origin/foo
Here Care common commits, Lare local commits, and Uis an upstream commit. If you are on a branch fooand you run git status, you will see "ahead of 3, for 1".
Here git gets these numbers:
git rev-list foo --not origin/foo: foo, origin/foo. , origin/foo ( U), : U C . foo , : L .
--count git rev-list, SHA-1 .
git rev-list origin/foo --not foo: , origin/foo, foo, U. ( --count, , .)
, foo --not origin/foo origin/foo..foo gitrevisions . ( git status , HEAD - . @{upstream} @{u} HEAD , , git status git rev-list --count ..@{u} git rev-list --count @{u}...)
rev-list , vs git cherry
, , feature, master, , feature master. git rev-list master..feature , feature, master, --count :
git rev-list --count master..feature
, , diff, "". , , feature , master did't, ( -) , master, :
D - E - F - G - H <-- feature
/
... - C - C
\
F' <-- master
F' - commit F. git rev-list feature, master, 5; git cherry feature, master, commit F , , F' F. , git cherry, 4, 5.