Skip to content

Instantly share code, notes, and snippets.

@wjljack
Forked from Xipiryon/count.sh
Created September 15, 2020 08:31
Show Gist options
  • Select an option

  • Save wjljack/cb62bd395418283892f90ae5a3ac2ccc to your computer and use it in GitHub Desktop.

Select an option

Save wjljack/cb62bd395418283892f90ae5a3ac2ccc 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment