使用 git 计算逻辑代码行数
Count logical lines of code with git
有没有办法用git计算c++/java项目的逻辑代码行数?此外,我还需要为作者计算它们。有什么建议吗?
如果您正在查看当前提交,请忽略方括号中的语句。
以下命令对项目中的所有行进行计数。
[commit=<some-commit>]
for file in $(git ls-files [--with-tree=$commit])
do
git cat-file -p [$commit]:$file
done |
wc -l
以下命令将按作者计算所有行数。
[commit=<some-commit>]
for file in $(git ls-files [--with-tree=$commit])
do
git blame [$commit] --line-porcelain -- $file
done |
sed -n 's/^author //p' |
sort |
uniq -c |
sort -r
感谢 the Git documentation for git blame 计算每个文件的作者行数。如果您修改正在查看的字段,您还可以抓取其他有用的信息。
Is there a way to count the logical lines of code of a c++/java project with git?
简答?没有。Git对代码没有特别了解。有一些工具可以做到,您可以在结帐时简单地 运行 它们。
I need to count them for author as well.
您可以使用 git blame
来告诉您谁写了什么行,但这些行将不是逻辑行。拆分为多行的单个语句将被计算多次。
有没有办法用git计算c++/java项目的逻辑代码行数?此外,我还需要为作者计算它们。有什么建议吗?
如果您正在查看当前提交,请忽略方括号中的语句。
以下命令对项目中的所有行进行计数。
[commit=<some-commit>]
for file in $(git ls-files [--with-tree=$commit])
do
git cat-file -p [$commit]:$file
done |
wc -l
以下命令将按作者计算所有行数。
[commit=<some-commit>]
for file in $(git ls-files [--with-tree=$commit])
do
git blame [$commit] --line-porcelain -- $file
done |
sed -n 's/^author //p' |
sort |
uniq -c |
sort -r
感谢 the Git documentation for git blame 计算每个文件的作者行数。如果您修改正在查看的字段,您还可以抓取其他有用的信息。
Is there a way to count the logical lines of code of a c++/java project with git?
简答?没有。Git对代码没有特别了解。有一些工具可以做到,您可以在结帐时简单地 运行 它们。
I need to count them for author as well.
您可以使用 git blame
来告诉您谁写了什么行,但这些行将不是逻辑行。拆分为多行的单个语句将被计算多次。