Get cloc (count lines of code ) difference between 2 commits by date Git

1.1k Views Asked by At

i tried the below command in git to get cloc difference between two commits using commit ids and i got the result in beautiful table.

cloc --git --diff <commit id1> <commit id2>

But i need a CLOC difference between commits but instead of using commit ids i need to use dates as a parameter to get the result.

1

There are 1 best solutions below

5
sytech On

Use git rev-list to get the commit SHAs you want for a particular date range.

For example, suppose you want to use the date range Jan 20, 2021 to Feb 20, 2021

branch=master
start_date=2021-01-20
end_date=2021-02-20

start_commit="$(git rev-list -n1 --before=${start_date} ${branch})"
end_commit="$(git rev-list -n1 --before=${end_date} ${branch})"

echo "Start commit for ${start_date} is ${start_commit}
echo "End commit for ${end_date} is ${end_commit}

Using this, you can plug $start_commit and $end_commit into your cloc command:

loc_count="$(cloc --git --diff ${start_commit} ${end_commit})"
echo "$loc_count"