0

I have a uni assignment to discuss the relationships in defective files for a given git repository. I am trying to generate a git log of the following format:

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

The best ive gotten so far is git log --name-only --pretty=format: | sort | uniq -c >results.txt which produces number of commits + file name

2
  • Can you add an example for the expected output format? Commented Nov 23, 2018 at 5:32
  • file1.java 10 55 4 file2.java 4 1734 8 file3.java 22 409 6 i dont need an exact format, i just need the 4 pieces of information in a text file Commented Nov 23, 2018 at 6:20

1 Answer 1

0

This script can do the job:

#!/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 

As an example, I made a clone of this repo from GitHub: https://github.com/GitSquared/edex-ui to the /opt directory. Then, I ran my script as ./repodetails.bash /opt/edex-ui. This generated a file named output.txt under /opt/edex-ui.

The output.txt file contains the required details in the following format:

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 
5
  • Sorry im completely new to git. How do i run this script exactly? I have the repository on my local machine. Also thanks a lot! Commented Nov 23, 2018 at 7:46
  • @user322394 1) Create a file anywhere in your system with the name repodetails.bash. 2) Copy the script contents from here to that file. 3) Run the script as bash repodetails.bash /path/to/local/repository. The remaining execution details are included in my answer. Commented Nov 23, 2018 at 8:05
  • @user322394 Here's a link to a tutorial site, with slightly more detailed instructions: javatpoint.com/steps-to-write-and-execute-a-shell-script Commented Nov 23, 2018 at 8:07
  • Im on windows 10. Still struggling to run this script. Commented Nov 23, 2018 at 8:51
  • This site is for Unix & Linux questions, and my script is therefore written for a Linux environment. If you have Git Bash on your Windows system, you can take a look at this: stackoverflow.com/q/36401147/6216002 Commented Nov 23, 2018 at 9:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.