git cmd 格式化日志

git cmd 格式化日志

我有一个大学作业来讨论给定 git 存储库的缺陷文件中的关系。我正在尝试生成以下格式的 git 日志:

file name + number of commits + current word count + number of contributors

到目前为止我得到的最好的git log --name-only --pretty=format: | sort | uniq -c >results.txt 结果是number of commits + file name

答案1

该脚本可以完成以下工作:

#!/bin/bash
# Invoke as repodetails.bash /path/to/git/repo

git_repo_path=$1

cd $git_repo_path
echo "" > output.txt

# Get a list of tracked files in the current repository.
file_list=$(git ls-tree -r HEAD --name-only)

for file in $file_list
do

# Get the count of commits by listing the commit history of the file.
commit_count=$(git log --oneline -- "$file" | wc -l)

# Use wc on the file to get the word count.
word_count=$(git show "HEAD:$file" | wc -w)

# Use the summary option of git shortlog to get a list of contributors.
author_count=$(git shortlog -s $file | wc -l)

echo "$file $commit_count $word_count $author_count" >> output.txt
done

作为示例,我从 GitHub 克隆了这个存储库:https://github.com/GitSquared/edex-ui到 /opt 目录。然后,我将我的脚本运行为./repodetails.bash /opt/edex-ui.这会生成一个output.txt名为/opt/edex-ui.

output.txt 文件包含以下格式的所需详细信息:

src/classes/modal.class.js 2 165 1
src/classes/netstat.class.js 8 305 1
src/classes/ramwatcher.class.js 5 257 2
src/classes/sysinfo.class.js 6 291 1
src/classes/terminal.class.js 31 906 2
src/classes/toplist.class.js 2 95 1
src/classes/updateChecker.class.js 4 190 1
src/package-lock.json 55 685 3
src/package.json 68 65 5
src/ui.html 20 161 1

相关内容