git log statistics code amount command

I read it today, one year is almost here, here are 170,000 code words, and then I want to count how many lines of code have been coded, as follows

1. Count someone's code submissions, including additions, deletions, total:

git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -

Result (author name replaced with *):

git log --author="*********" --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
added lines: 18768 removed lines : 9624 total lines: 9144

Less than 10,000 lines, a little ashamed...

2, The top 5 repository submitters in the number of submissions (if you want to see all, just remove the head pipeline)

git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5

All ranking results

5168 ys.y
3220 ysz
2052 ss
1860 wx
1180 j.l
1179 zc
916 gcz
801 eGG
761 scy
756 q.z
666 jl.x
602 cage
590 kirk
575 gk.c
525 yj.y
432 qb
391 zh.s
345 j.x
329 cw
280 h.y
168 allen
93 hale
余下略...

3. The mailboxes of the top 5 warehouse submitters in the number of submissions: This statistic may not be too accurate, because many people have different mailboxes, but will use the same name

git log --pretty=format:%ae | gawk -- '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }' | sort -u -n -r | head -n 5

4. Statistics on the number of code contributors

git log --pretty='%aN' | sort -u | wc -l

5, the total number of submissions statistics

git log --oneline | wc -l

6, the number of lines of code added or modified

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'

7, Count the amount of code changes in a certain period of time

git log --pretty=tformat: --since ==2017-05-11 --until=2018-03-07 --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }'

 

git log parameter description:
--author specifies the author
--stat displays the file modification statistics for each update, and lists the specific file list

--numstat Count the number of modified lines in each commit, including adding, deleting, and listing the file list
--shortstat Counting the number of modified lines in each commit, including adding, deleting, but not listing the file list

 
-p option Expand to show the content difference of each commit, use -2 to show only the last two updates.
For example: git log -p -2
--name-only only show the list of modified files after the commit information
--name-status show list of new, modified, deleted files
--abbrev-commit display only the first few characters of SHA-1, not all 40 characters
--relative-date use shorter relative time display (eg, "2 weeks" ago" )
--graph display an ASCII graphical representation of the branch-merge history
--pretty use a different format to display historical commit information. Available options include oneline, short, full, fuller and format (followed by the specified format)
       for example: git log --pretty=oneline ; git log --pretty=short ; git log --pretty=full ; git log --pretty= fuller;
--pretty=tformat: You can customize the record format to be displayed, so that the output is convenient for later programming extraction analysis.
       For example: git log --pretty=format:""%h - %an, %ar : %s""

--since limit the range of output,
for example: git log --since=2.weeks show the commits of the last two weeks
option description                
-(n) only show the latest n commits                    
--since, --after show only the specified time subsequent commits.                    
--until, --before Show only commits before the specified time.                  
--author Show only commits related to the specified author.                
--committer Show only commits related to the specified committer.

Some examples:

git log --until=1.minute.ago // everything from one minute ago

log git log --since=1.day.ago //within one day

log git log --since=1.hour.ago //within an hour

log git log --since=`.month.ago --until=2.weeks.ago //One month ago to half a month ago

log git log --since ==2013-08.01 --until=2013-09-07 //A certain period of time

log git blame to see the relevant history of a file
For example: git blame index.html --date short

 

Reference link:

http://blog.csdn.net/dwarven/article/details/46550117

http://blog.csdn.net/liusuihui/article/details/52885417

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325301771&siteId=291194637