Skip to content

Instantly share code, notes, and snippets.

@Xipiryon
Last active June 25, 2024 10:29
Show Gist options
  • 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
@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