Last active
June 25, 2024 10:29
-
-
Save Xipiryon/415a908c34b6dce44183a7d9b6c35416 to your computer and use it in GitHub Desktop.
Git: Get commit count for specific folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
Faster:
git rev-list --count HEAD -- <path>