git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --numstat --author="$name" | awk 'BEGIN{add=0;subs=0;loc=0} {if($1~/^[0-9]+/){add += $1; subs += $2; loc += $1 + $2 }} END {printf "%s\t%s\t%s\n", add, subs, loc }'; done;
请cd到指定代码仓库目录下,然后运行上面的命令,可以看到如下输出,
peipeihh 13594 275 13869
每列的数字意义如下,
第一列:代码提交人
第二列:提交的新增代码行数
第三列:提交的删除代码行数
第四列:所有提交的代码行数
2. 批量的Git代码仓库
若是有批量的Git代码仓库,则可以使用如下批量分析脚本。
# 1. parse the date of start and end
sinceDate=$1
untilDate=$2
if [ ! $sinceDate ]; then
sinceDate="1970-01-01"
fi
if [ ! $untilDate ]; then
untilDate=`date '+%Y-%m-%d'`
fi
echo "the period of analysis: sinceDate = $sinceDate, untilDate = $untilDate"
# 2. prepare the repository folder
repoTmp=$PWD
repoList="$PWD/repoList.txt"
repoLocalDir="$PWD/repoLocal"
repoReportFile="$PWD/tmpReport.txt"
repoFinalReportFile="$PWD/finalReport.txt"
if [ -d "$repoLocalDir" ]; then
rm -rf $repoLocalDir;
fi
mkdir -p $repoLocalDir;
if [ -f "$repoReportFile" ]; then
rm $repoReportFile;
fi
touch $repoReportFile;
if [ ! -f "$repoList" ]; then
echo "Cannot find repoList.txt, please create it and list all the git repositories to be analyzed, a format is as following, "
echo "```"
echo "git@gitee.com:pphh/simple-demo.git master"
echo "```"
exit 1
fi
# 3. clone the git repo into local and do the investigation
i=1
cat $repoList | while read line
do
cd $repoLocalDir
repoDef=( $line )
repoName=${repoDef[0]}
repoBranch=${repoDef[1]}
if [ -z $repoName ]; then
continue
fi
if [ -z $repoBranch ]; then
repoBranch="master"
fi
repoFolder="./$i-repo-$repoBranch"
let i++
echo
echo "start to clone the repository: $repoName, branch = $repoBranch, folder = $repoFolder"
git clone $repoName -b $repoBranch $repoFolder
echo "clone is completed!"
cd $repoFolder
echo "try to investigate the submission status of the repository: $repoName, branch = $repoBranch"
git log --format='%aN' | sort -u | while read name; do git log --numstat --author="$name" --since="$sinceDate" --until="$untilDate" | awk 'BEGIN {add=0;subs=0;all=0} {if($1~/^[0-9]+/){add += $1; subs += $2; all += $1 + $2 }} END {printf "'$name'\t%s\t%s\t%s\n", add, subs, all }' >> $repoReportFile; done;
done
# 4. merge the results
cat $repoReportFile | awk '{ newLines[$1]+=$2;deleteLines[$1]+=$3;all[$1]+=$4 } END {for (i in all) print i,newLines[i],deleteLines[i],all[i];}' > $repoFinalReportFile
rm $repoReportFile
echo
echo "name\tnew-code-lines\tdelete-code-lines\tall"
cat $repoFinalReportFile
[main] ERROR org.springframework.boot.SpringApplication 858 | Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testHttpController': Unsatisfied dependency expressed through field 'xxxHttpClientManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxHttpClientManager' defined in URL [jar:file:/xxx/xxxHttpClientManager.class]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/GenericHttpMessageConverter
Caused by: java.lang.NoClassDefFoundError: org/springframework/http/converter/GenericHttpMessageConverter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.xxx.http.client.xxxHttpClientManager.<>(xxxHttpClientManager.java:63)
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.GenericHttpMessageConverter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 60 common frames omitted
public static void main(String[] args) {
System.out.println("this is a simple app...");
/**
* 在加载simple-agent的情况下,会报如下异常,
* java.lang.ClassNotFoundException: org.springframework.http.converter.GenericHttpMessageConverter
*/
FastJsonHttpMessageConverter fastJsonMsgConverter = new FastJsonHttpMessageConverter();
System.out.println("fastJsonMessageConverter has been created successfully.");
}
$ java -javaagent:./simple-agent/target/simple-agent.jar -jar ./simple-app/target/simple-app.jar
this is a demo agent...
this is a simple app...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.NoClassDefFoundError: org/springframework/http/converter/GenericHttpMessageConverter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.pphh.demo.SimpleApp.main(SimpleApp.java:17)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.GenericHttpMessageConverter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more