Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make git list all changed files of a certain type in a specific path for a specific bug?

I would like to know how to make git list all changed files

  • of a certain type (e.g. all php files)
  • filed under a certain bug no. or which are still uncommitted
  • and are in a specific path

I'll start with laying out an example situation for my question.

Say I have changed the following files:

Uncommitted changes

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

Commit 3
Commit message: "Bug xyz: Made some changes"

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

Commit 2
Commit message: "Bug xyz: Made some more changes"

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

Commit 1
Commit message: "Bug abc: Note that this is another bug"

/site/login.php

Say I'm still working on bug xyz. Now I need a list of all php files that have been changed so far in the site directory for this bug. So I would need the following list as output:

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

What command can do this?

like image 525
Iljaas Avatar asked Apr 05 '13 13:04

Iljaas


1 Answers

This is close:

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

The --grep argument is applied to the commit messages. The single quotes on the files argument ensures that git does the expansion.

A test:

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

The file expansion might need something to handle subdirectories. Sort of:

git log --oneline --grep=a -- '*/a.*' 'a.*'
like image 145
GoZoner Avatar answered Oct 21 '22 03:10

GoZoner