git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Quick command to count commits

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 6, 2009, 18:55 UTC
Message-ID
<20090106185543.GB24578@spearce.org>
In-Reply-To
<1231267896595-2118851.post@n2.nabble.com>
Henk <henk_westhuis@hotmail.com> wrote:
Show 6 quoted lines
> For GitExtensions (windows git ui) I need a command to count all commits. I
> now use this command:
> git.cmd rev-list --all --abbrev-commit | wc -l
> 
> This works perfect but its very slow in big repositories. Is there a faster
> way to count the commits?

No. But drop the --abbrev-commit flag, abbreviating the object ids would take longer than just dumping the full 40 bytes to stdout. It requires a scan of parts of the object database for every commit to determine what is a unique abbreviation.

This isn't a very common operation. Its expensive to do, as you can see. What's the reason for supplying it, and needing it so quickly? Nobody really cares how many commits are in their history, unless they are trying to produce stats to describe how big their repository is. In which case the size of the .git/objects/pack *.pack and *.idx files is much more relevant, especially the .idx files as it gives a really quick estimate on the number of total objects in the repository.

-- 
Shawn.
Previous: HenkNext: Linus Torvalds
Message 2 of 4 in “Quick command to count commits”
  1. HenkJan 6, 2009
  2. Shawn O. PearceJan 6, 2009
  3. Linus TorvaldsJan 6, 2009
  4. Ted PavlicJan 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.