Skip to content

Instantly share code, notes, and snippets.

@Xipiryon
Last active January 8, 2024 14:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Xipiryon/415a908c34b6dce44183a7d9b6c35416 to your computer and use it in GitHub Desktop.
Save Xipiryon/415a908c34b6dce44183a7d9b6c35416 to your computer and use it in GitHub Desktop.
Git: Get commit count for specific folder
#!/bin/bash
git log --name-only --pretty=format: -- $1 | sort | uniq -c | head -n 1
# --name-only = Show only names of changed files
# --pretty=format: = Remove the information, leaving only filenames
# -- $1 = Only show commits in that path (expected as argument)
# first sort will make sure things are sorted, so ...
# ... uniq -c can effectively merge all duplicates lines, counting them
# The first line is the total number of commits in that folder, retrieved by head -n 1
@gonsolo
Copy link

gonsolo commented May 11, 2022

3x faster: git log . | grep ^commit | wc -l

@rmaalouf
Copy link

Faster:
git rev-list --count HEAD -- <path>

@gonsolo
Copy link

gonsolo commented Nov 10, 2022

Yep, 35 vs 54 seconds counting 1.125.973 commits in the Linux kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment