我的团队使用Visual Studio数据库项目,使用github作为源代码控制。我想为每个文件生成一行报告,其中包含以下信息:
我不关心涉及哪个提交。我只想要最后影响主分支上的文件。
答案 0 :(得分:2)
function report(){
file=$1
#commit=$(git log -1 --pretty=%H -- "$file")
#Edit: use the following command instead, in order to deal with file paths with a space.
commit=$(git log -1 --pretty=%H -- "$file")
#if you want to ignore the files unchanged since the root commit, you could use:
#commit=$(git log -1 --pretty=%H --min-parents=1 -- "$file")
authorname=$(git log -1 $commit --pretty=%an)
commitdate=$(git log -1 $commit --pretty=%cd --date=short)
commitcomment=$(git log --format=%b -n 1 $commit)
status=$(git show $commit --pretty=%h --name-status | grep "$file" | awk '{print $1}')
case $status in
A ) status=Added;;
C ) status=Copied;;
D ) status=Deleted;;
M ) status=Modified;;
R ) status=Renamed;;
T ) status=Changed;;
U ) status=Unmerged;;
B ) status=Broken;;
* ) status=Unknown;;
esac
echo "$commit|$file|$authorname|$commitdate|$status|$commitcomment"
}
#git ls-files | while read line; do report $line; done > report.txt
#Edit:use the following command instead, in order to get all files, including deleted files.
git log --pretty="/ %h" --name-only | grep -v ^$ | grep -v "/ " | sort -u | while read line;do report "$line"; done; > report.txt
然后你可以将report.txt导入excel,用“|”分割字段。
我的代码可能效率不高但效果不错。