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-uioutput.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

おすすめ記事