5

我想知道如何让 git 列出所有更改的文件

  • 某种类型的(例如所有 php 文件)
  • 根据某个错误编号提交。或尚未提交的
  • 并且在特定的路径中

我将首先为我的问题列出一个示例情况。

假设我更改了以下文件:

未提交的更改

/site/main.php
/site/main.html
/site/includes/lib.php

提交 3
提交消息:“错误 xyz:进行了一些更改”

/site/main.php
/site/main.html
/site/main.js
/test/test.php
/test/test.html

提交 2
提交消息:“错误 xyz:进行了更多更改”

/site/main.php
/site/main.html
/site/includes/include.php

提交 1
提交消息:“错误 abc:注意这是另一个错误”

/site/login.php

假设我仍在研究错误 xyz。现在我需要一个列表,列出到目前为止在站点目录中已针对此错误更改的所有 php 文件。所以我需要以下列表作为输出:

/site/main.php
/site/includes/lib.php
/site/includes/include.php

什么命令可以做到这一点?

4

1 回答 1

9

这很接近:

git log --grep=xyz -- '*.php'

--grep参数应用于提交消息。files 参数上的单引号确保git进行扩展。

一个测试:

ebg@ebg(328)$ git log --oneline
f687708 bar x, y, not a
dfb4b96 foo d, e, f
df18118 foo a, b, c
ebg@ebg(329)$ git log --oneline --grep=a
f687708 bar x, y, not a
df18118 foo a, b, c
ebg@ebg(330)$ git log --oneline --grep=a -- 'a.*'
df18118 foo a, b, c

文件扩展可能需要一些东西来处理子目录。有点:

git log --oneline --grep=a -- '*/a.*' 'a.*'
于 2013-04-05T14:38:56.897 回答