0

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.

Basil Musa
  • 8,198
  • 6
  • 64
  • 63

1 Answers1

0

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"
sytech
  • 29,298
  • 3
  • 45
  • 86
  • sytech , how to run this commands in command prompt – Anusha G Feb 15 '22 at 05:37
  • cloc is not wokring in gitbash – Anusha G Feb 15 '22 at 08:38
  • @AnushaG the commands are the same in Windows, with the proper tools installed. The syntax would change a bit with the variables, but the principle remains exactly the same. -- `cloc` is not included in most Linux distributions or Windows by default, you'll need to [install it](http://cloc.sourceforge.net/#apt-get) – sytech Feb 15 '22 at 18:57
  • can you suggest any other commands – Anusha G Feb 16 '22 at 06:23
  • can you tell me how to run that commands in command prompt , i use set method to initialize the date and start_commit,end_commit but i am not getting the result – Anusha G Feb 16 '22 at 17:48