Using the git diff --shortstat my_branch master
is a great way to tell how many files changes and the insertions and deletions. I read the git diff documentation, but I couldn't find a way to tell the number of commits between my_branch
and master
. Does that exist?
Asked
Active
Viewed 1.8k times
47

sobi3ch
- 2,555
- 2
- 31
- 41

nickcoxdotme
- 6,567
- 9
- 46
- 72
-
are you asking for (#commits on master not on my_branch) + (#commits on my_branch not on master) ? – Andrew C Oct 16 '14 at 20:56
5 Answers
43
I think you could try:
git log --oneline mybranch ^master
For the exact count:
git log --oneline mybranch ^master | wc -l
Should give you the information you want.

Daniel Williams
- 8,673
- 4
- 36
- 47
-
2
-
6It means to select the log starting with mybranch and ending at and not including master. – Daniel Williams Sep 19 '17 at 19:05
38
I found this to be much simpler:
git rev-list --count my-branch ^master

etech
- 2,548
- 1
- 27
- 24
-
-
1
-
3If you're already on `my-branch` you can use `HEAD` instead: `git rev-list --count HEAD ^master` – David Jan 06 '21 at 09:20
-
`my-branch ^master` is the same as `^master my-branch` and `master..my-branch`. This notation lists all commits which are in `my-branch` but are not yet in `master`. You can also use `master...my-branch` (which is the same as `my-branch...master` or just `...master` if you're currently on `my-branch`) which lists commits unique to `my-branch` and `master`, i.e. how much the two branches diverged. – SnakE May 24 '22 at 13:21
25
I could not get etech's answer to work, but this works for me on OS X:
git rev-list --count master..my-branch
my-branch
can be omitted for changes on the current branch.

mvr
- 1,732
- 16
- 11
4
Another option. The hashes/number are just examples
$ git checkout my_branch
$ git cherry master
+ 950b187c4b28844680df7008cfa3b348c1a46016
+ 109e427cbe84c3c8fc0ac2fbfb5120bcc2511933
+ 9bc217c0bcabbd6aa4ba88bbaaad23805994f90d
+ 74e054614a1bb1c442fbcf53926dcb910097321c
+ b34ae1ce8a58e0cbdbe1657ebca81a3036d7c72d
Will give a list of commit hashes that are in my_branch but not in master
$ git checkout my_branch
$ git cherry master | wc -l
5
Will give the number of commits that are in my_branch but not in master
Read more about git cherry here
0
This gives me the number of commits I've made to branch_being_merged_in
since branching from branch_A
:
git log --pretty=%H branch_A..branch_being_merged_in | wc -l