有没有简单的方法来计算Git中两次提交之间更改的行数?

我知道我可以做一个git diff,并数行,但这似乎很乏味。我还想知道如何做到这一点,在行计数中只包括我自己的提交。


当前回答

git log --numstat 

只给你数字

其他回答

git diff --shortstat

给出修改和添加的行数。这只适用于未分阶段的更改。与树枝比较:

git diff --shortstat some-branch

假设你想比较abcd123(第一次提交)和wxyz789(最后一次提交)之间的所有提交,包括:

git log wxyz789^..abcd123 --oneline --shortstat --author="Mike Surname"

这将给出如下简洁的输出:

abcd123 Made things better
 3 files changed, 14 insertions(+), 159 deletions(-)
wxyz789 Made things more betterer
 26 files changed, 53 insertions(+), 58 deletions(-)
git log --numstat 

只给你数字

如果您想查看更改,包括在您的分支和另一个分支之间更改的行号,

git diff the_other_branch_name --stat
git diff --stat commit1 commit2

EDIT:您还必须指定提交(如果没有参数,它将工作目录与索引进行比较)。如。

git diff --stat HEAD^ HEAD

比较HEAD和HEAD的父类。