Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the number of commits in a Git repo when cloning with --depth=1

Tags:

git

To find the number of commits on a git branch you can do:

$ git rev-list --count HEAD
920

However, if you initially clone with --depth=1, that doesn't work:

$ git clone https://github.com/ndmitchell/hoogle.git --depth=1
$ cd hoogle
$ git rev-list --count HEAD
1

Is there any way to get the speed and reduced network traffic of a --depth=1 clone, but then also get the count of the number of commits?

like image 908
Neil Mitchell Avatar asked Aug 18 '15 09:08

Neil Mitchell


1 Answers

Is there any way to get the speed and reduced network traffic of a --depth=1 clone, but then also get the count of the number of commits?

I'm pretty sure you can't.

As you know, --depth=1 only retrieves the most recently pushed commit. That means when you clone with a depth of 1 you get 1 commit and only that single commit, with no history at all attached to it.

As far as your local repository is concerned, there is no history, just this 1 commit.

As is also mentioned in the docs

--depth

Create a shallow clone with a history truncated to the specified number of revisions.

What I also find interesting that even if you'd check the origin

$ git rev-list --count origin/master
$ git log origin/master

they'd both only show 1 commit, too.

like image 178
Tim Avatar answered Sep 28 '22 10:09

Tim