我想要计入git存储库中的总代码行数。 我在谷歌找到了答案。
git ls-files -z | xargs -0 cat | wc -l
它在本地存储库中运行良好。
但。 我想要计入远程存储库。
所以,我试过了。
git ls-files -z /home/bjyoo/repositories/root/localfiletest.git | xargs -0 cat | wc -l
,
git ls-files -z --git-dir=/home/bjyoo/repositories/root/localfiletest.git | xargs -0 cat | wc -l
和
git --git-dir=/home/bjyoo/repositories/root/localfiletest.git --ls-files | xargs -0 cat | wc -l
所有命令都失败了
有谁知道如何计算总代码行数?
I wanna count to total lines of codes in git repository. I've found the answer in google.
git ls-files -z | xargs -0 cat | wc -l
It works well in local repository.
but. I want to count in remote repository.
so, I tried.
git ls-files -z /home/bjyoo/repositories/root/localfiletest.git | xargs -0 cat | wc -l
,
git ls-files -z --git-dir=/home/bjyoo/repositories/root/localfiletest.git | xargs -0 cat | wc -l
and
git --git-dir=/home/bjyoo/repositories/root/localfiletest.git --ls-files | xargs -0 cat | wc -l
all command failed.
does anyone knows how to count total lines of code?
最满意答案
虽然VonC对于命令失败的原因是正确的,但仍有一种方法可以计算存储库中的行,即使此存储库是裸的。
为了实现这一点,你必须使用git show从git打印特定版本的文件内容。
假设您当前在存储库中,这样的命令可能看起来像这样。
for file in $(git ls-tree --name-only -r HEAD); do git show HEAD:"$file" done | wc -l如果要从其他文件夹执行命令,可以在git关键字后使用--git-dir 。
for file in $(git --git-dir=<path-to-repo> ls-tree --name-only -r HEAD); do git --git-dir=<path-to-repo> show HEAD:"$file" done | wc -l
我们使用git ls-tree列出存储库中的所有文件,原因是ls-files在裸存储库中不起作用。 然后我们使用git show和特定版本打印文件的内容。
您可以查看ls-tree文档和show文档,以准确了解命令正在执行的操作。
While VonC is correct on the reason why your commands are failing, there still is a way to count the lines in a repository, even if this repository is bare.
For this to work you have to make git print the content of the files from a specific revision which is possible using git show.
Such a command could look like this, assuming you are currently in the repository.
for file in $(git ls-tree --name-only -r HEAD); do git show HEAD:"$file" done | wc -lIf you want to execute the command from a different folder you can use --git-dir after the git keyword.
for file in $(git --git-dir=<path-to-repo> ls-tree --name-only -r HEAD); do git --git-dir=<path-to-repo> show HEAD:"$file" done | wc -l
We are using git ls-tree to list all files in the repository, the reason being that ls-files doesn't work in a bare repository. Then we print the content of the file using git show combined with a specific revision.
You can take a look at the ls-tree documentation and the show documentation to understand exactly what the commands are doing.
更多推荐
发布评论