2

I have an assignment to count all the changes from all the files from a git open-source project. I know that if I use:

git log --pretty=oneline <filename> | wc  -l

I will get the number of changes of that file ( I use git bash on Windows 10)

My idea is to use

find .

and to redirect the output to the git command. How can I do the redirecting? I tried :

$ find . > git log --pretty=online | wc -l
0
find: unknown predicate `--pretty=online'

and

$ find . | git log --pretty=online | wc -l
fatal: invalid --pretty format: online
0

2 Answers 2

2

You can do much better than that,

git log --pretty='' --name-only | sort | uniq -c

That's "show only the names of files changed in each commit, no other metadata, sort that list so uniq can easily count the occurrences of each'

Sign up to request clarification or add additional context in comments.

Comments

0

You'll need to loop over the results of find.

find -type f | grep -v '^\./\.git' |
while read f; do
    count=$(git log --oneline ${f} | wc -l)
    echo "${f} - ${count}"
done | grep -v ' 0$'

Your find is okay, but I'd restrict it to just files (git doesn't track directories explicitly) and remove the .git folder (we don't care about those files). Pipe that into a loop (I'm using a while), and then your git log command works just fine. Lastly, I'm going to strip anything with a count of 0, since I may have files that are part of .gitignore I don't want to show up (e.g., things in __pycache__).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.