[Git] git commit 통계 보기
ITWeb/개발일반 2019. 3. 19. 11:27파일명 마음에 안들지만 그냥 귀찮으니 그대로 올립니다.
$ tree -f
.
├── ./git-stats-period.sh
├── ./git-stats.sh
└── ./project_clone.sh
$ ./git-stats-period.sh 1 git-stats
git-stats-period.sh) 통계 추출 메인 스크립트
#!/bin/bash
PERIOD=$1
CLONE_DIR=$2
if [ "$#" -ne 2 ]
then
echo "example $ ./git-stats-period.sh PERIOD CLONE-DIR"
echo "example $ ./git-stats-period.sh 7 git-temp"
exit 0
fi
mkdir -p $CLONE_DIR
./project_clone.sh $CLONE_DIR
cd $CLONE_DIR
rm -f ./git-stats-temp.log
rm -f ./git-committers.log
for (( idx=1; idx<=$PERIOD; idx++ ))
do
# 디렉토리 목록을 가져오고, all.log 파일은 삭제
for dir in $(ls -d */)
do
echo ${dir%%/}
echo "rm -f ./${dir%%/}/git-stats-all.log"
echo "../git-stats.sh $idx ${dir%%/}"
rm -f ./${dir%%/}/git-stats-all.log
../git-stats.sh $idx ${dir%%/}
done
done
sort ./git-committers.log | uniq > ./git-uniq-committers.log
git-stats.sh) 통계 추출 실행 스크립트
#!/usr/bin/env bash
pwd
cd $2
#git stash
#git pull
#exit 0
DAYS_AGO=$1
DATE=`date -v -"$DAYS_AGO"d +%F`
PWD=`pwd`
rm -f ./git-stats-$DATE.log
echo "Date : $DATE" > "git-stats-$DATE.log"
echo "Date : $DATE" >> "git-stats-all.log"
echo "Date : $DATE" >> "../git-stats-temp.log"
# This script must exist under git repository.
echo "[Commit Statistics]" >> "git-stats-$DATE.log"
echo "[Commit Statistics]" >> "git-stats-all.log"
echo "[Commit Statistics]" >> "../git-stats-temp.log"
# total commit stats
USER_COUNT=`git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --format='%aN %ce' | sort -u | wc -l`
echo "Total Commit Users : $USER_COUNT" >> "git-stats-$DATE.log"
echo "Total Commit Users : $USER_COUNT" >> "git-stats-all.log"
echo "Total Commit Users : $USER_COUNT" >> "../git-stats-temp.log"
git log --shortstat --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed: ", files, "lines inserted: ", inserted, "lines deleted: ", deleted }' >> "git-stats-$DATE.log"
git log --shortstat --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed: ", files, "lines inserted: ", inserted, "lines deleted: ", deleted }' >> "git-stats-all.log"
git log --shortstat --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed: ", files, "lines inserted: ", inserted, "lines deleted: ", deleted }' >> "../git-stats-temp.log"
echo "" >> "git-stats-$DATE.log"
echo "" >> "git-stats-all.log"
echo "" >> "../git-stats-temp.log"
echo "[Committers]" >> "git-stats-$DATE.log"
echo "[Committers]" >> "git-stats-all.log"
echo "[Committers]" >> "../git-stats-temp.log"
# commit user list
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --format='%aN %ce' | sort -u >> "git-stats-$DATE.log"
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --format='%aN %ce' | sort -u >> "git-stats-all.log"
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --format='%aN %ce' | sort -u >> "../git-committers.log"
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --format='%aN %ce' | sort -u >> "../git-stats-temp.log"
echo "" >> "git-stats-$DATE.log"
echo "" >> "git-stats-all.log"
echo "" >> "../git-stats-temp.log"
echo "[Commit Logs]" >> "git-stats-$DATE.log"
echo "[Commit Logs]" >> "git-stats-all.log"
echo "[Commit Logs]" >> "../git-stats-temp.log"
# each user commit stats
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --pretty=format:'"%an", "%aD", "%s",' --shortstat --no-merges >> "git-stats-$DATE.log"
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --pretty=format:'"%an", "%aD", "%s",' --shortstat --no-merges >> "git-stats-all.log"
git log --before="$DATE 23:59:59" --after="$DATE 00:00:00" --all --pretty=format:'"%an", "%aD", "%s",' --shortstat --no-merges >> "../git-stats-temp.log"
project_clone.sh) git repo clone 스크립트