0

我没有看到任何明显的方法,但是 git 一次又一次地证明比我想象的更灵活,所以......

我想找到引入大量代码更改的提交,所以我想通过插入或删除的行数(一起或单独)来限制它们。有没有办法做到这一点?

4

1 回答 1

3

git log --stat

commit e2b97c53727bd66c143713d13399ff4242e4ff06
Author: John Hobbs 
Date:   Thu Nov 4 17:01:14 2010 -0500
    Switched to jQuery Mobile. It's awesome.
 application/classes/controller/item.php    |   77 +++++++++++++---------------
 application/classes/controller/project.php |    4 +-
 application/classes/controller/site.php    |    2 +
 application/classes/controller/user.php    |    5 +-
 application/classes/form.php               |    2 +-
 application/views/item/add.php             |   27 +++-------
 application/views/item/index.php           |   19 ++-----
 application/views/item/view.php            |   11 +++--
 application/views/message/basic.php        |   13 +++++
 application/views/mobile.php               |   64 ++++++++++++++++++-----
 application/views/project/add.php          |    5 +--
 application/views/project/index.php        |   28 ++++------
 application/views/project/view.php         |   19 ++-----
 application/views/user/index.php           |   25 +--------
 application/views/user/login.php           |   14 +++--
 application/views/user/register.php        |   20 ++++---
 16 files changed, 165 insertions(+), 170 deletions(-)

此处的示例输出)

然后在视觉上查找长 +/- 符号或使用--numstat并将其传递给另一个命令以对其进行过滤。

man git log


如果您需要对其进行过滤而不是在视觉上进行过滤(--shortstat按照 Antoine 的建议):

$ git log --pretty=oneline --shortstat 

这将为您提供如下输出:

$ git log --pretty=oneline --shortstat
19791900f886e7a5f92b7cf3536053c863bec067 fix tab title, system menu, and a focus
 2 files changed, 108 insertions(+), 65 deletions(-)
b52941150046cdb455c38e3f9bc133d6ba8f721f give tab a wndproc, change time to be
 1 files changed, 65 insertions(+), 20 deletions(-)
ae5c18524b4a02b264fe26319ce2c9cf7dbff6b2 Fix window style of parent window
 1 files changed, 1 insertions(+), 1 deletions(-)
8f94ad9bbbb2fec42feccda43374b13eda55c018 Add .gitignore to ignore some MSVC file
 1 files changed, 10 insertions(+), 0 deletions(-)

通过管道将其传输到 awk,搜索 'files changed, ',如果插入次数大于 50,则打印匹配行和上一行:

$ git log --pretty=oneline --shortstat | awk '/files changed, / && $4 > 50 {print x; print};{x=$0}'

19791900f886e7a5f92b7cf3536053c863bec067 fix tab title, system menu, and a focus
 2 files changed, 108 insertions(+), 65 deletions(-)
b52941150046cdb455c38e3f9bc133d6ba8f721f give tab a wndproc, change timer
 1 files changed, 65 insertions(+), 20 deletions(-)

一些 awk 参数的来源:http: //unstableme.blogspot.com/2008/05/print-currentnextprevious-line-using.html

于 2012-07-04T18:56:40.530 回答