2

Trying to run a script from: Git blame: statistics which is supposed to:

To give me a statistic of how much lines (of code) are currently in the repository originating from each committer.

Specifically:

git ls-tree -r -z --name-only HEAD -- /.c | xargs -0 -n1 git blame \ --line-porcelain HEAD |grep "^author "|sort|uniq -c|sort -nr

I am getting the following error and can't understand why:

cannot stat path 'HEAD': No such file or directory when running when running git blame script

Please note I am using git bashand not an actual linux system. Could this be making the difference?

Update

Apparently the command I am running is not identical. I just copied and pasted the command again:

git ls-tree -r -z --name-only HEAD -- */*.c | xargs -0 -n1 git blame \
--line-porcelain HEAD |grep  "^author "|sort|uniq -c|sort -nr

Update2

So the problem specifically seems to be related to -- */*.c . The original command suggested by the accepted answer works correctly:

git ls-tree --name-only -z -r HEAD|egrep -z -Z -E '\.(java)$' \
>   |xargs -0 -n1 git blame --line-porcelain|grep "^author "|sort|uniq -c|sort -nr
Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • Git blame needs to be run on _files_, though you can specify a particular commit. Maybe you should update your question with what you think your command is actually supposed to be doing? – Tim Biegeleisen Oct 18 '17 at 09:54
  • to give me a statistic of how much lines (of code) are currently in the repository originating from each committer. This is what the code should do. – Menelaos Oct 18 '17 at 09:55
  • I'm not a Linux guru. Where is the filename for `git blame` coming from in your command? – Tim Biegeleisen Oct 18 '17 at 09:56
  • The basic concept is that the list of filenames are produced from `git ls-tree `. Then these are piped to git blame. The other answer has more than 100 upvotes so theoretically it should work for me as well. Thanks...It is a bit intricate it seems. Thanks! – Menelaos Oct 18 '17 at 09:58
  • I [found that answer](https://stackoverflow.com/questions/4589731/git-blame-statistics) and your command is not completely identical. – Tim Biegeleisen Oct 18 '17 at 10:03
  • https://stackoverflow.com/a/13687302/1688441 . What is the difference? something with the characters?? :( – Menelaos Oct 18 '17 at 10:07
  • So I'm guessing that did not make a difference? Well all I can suggest is that you take the command apart, left to right, and make sure each piece is working. Obviously, by the last step you know it will fail, but maybe you will uncover something obvious in the process. – Tim Biegeleisen Oct 18 '17 at 10:10
  • @Tim Biegeleisen very good suggestion. The problem was with the first command in the pipe. once I changed it a bit and simplified it, it is working! – Menelaos Oct 18 '17 at 11:06

0 Answers0