如何在Gitlab中计算两个提交之间的代码行数变化?

4

我需要在特定时间段内计算源代码中的行更改数。

也就是说,通过使用提交ID,我可以知道源代码中的行更改数吗?

我不需要每个用户的行更改。我需要在那些提交之间所有行更改的数量。

我的Gitlab Community Edition版本是8.14.3。

更新

我所有的源代码都存在于mycompany.gitlab.com中。我该如何解决上述问题?


Gitlab是一项服务,而Git是一种工具。您的问题与Gitlab有何特定关系? - ceving
@ceving,我在问题中进行了更新。这样足够了吗?还需要我解释更多吗? - user6874415
3个回答

7
在你的Git工作目录中运行以下命令:
git diff <commit-1> <commit-2> --shortstat

您应该会得到以下输出结果:
7 files changed, 39 insertions(+), 107 deletions(-)

我尝试了下面的代码。但对我来说没有起作用。 git diff <155ee1c3> <bb674347> --shortstat我得到了异常 < 在此时是意外的。 - user6874415
我在哪里犯了错误? - user6874415
1
@Arunald 使用 git diff 155ee1c3 bb674347 --shortstat 替代。符号“<>”仅为格式指示。 - Robin Xing
我发现这个答案是在寻找如何使用分支的情况下找到的。--shortstat 在那里也有效。例如,我可以使用 git diff master --shortstat 比较我的分支和主分支上的更改行数。 - Erdős-Bacon

0

所有引用的代码均可在 https://docs.gitlab.com/ee/api/commits.html 中找到。

获取所有提交(包括 sinceuntil 参数): https://gitlab.example.com/api/v3/projects/:project_id/repository/commits

响应: enter image description here

获取提交的差异: https://gitlab.example.com/api/v3/projects/:project_id/repository/commits/:sha/diff

enter image description here

将上述终端节点中的diff字段拆分,以获取每个提交所更改的行并进行求和。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接