How to have git output only files related to an issue?

Viewed 50

Our commit messages are formatted like this:
PROJECT_NAME-ISSUE_NUM commit msg.

Question: How can I search for files that were changed by developer working on specific issue?

Note that I need only file names. For the purpose of this question, I don't care for commit messages, diff or anything else. Filenames. Once.

Shell script is ok.

Things that got me the closest:

  • git log --name-status --one-line --grep ISSUE_NUM
    I get commit messages I don't care about and same file is included multiple times, if it was changed in multiple commits.

  • git diff origin/master...HEAD --name-status --grep ISSUE_NUM
    Seems to include all files that differ between origin/master and current branch, not only the ones that were changed by developer working on that specific issue.

2 Answers

I'd do a string filter on a diff, along the lines of :

git diff --name-only origin/master...HEAD -S"ISSUE_NUM"

You can check the doc for details, or variants with regular expressions if need arises.

Your first solution is nearly correct, but you're getting the subject of the commit message with --oneline. You want a less verbose format, such as an empty string. Just pipe the output to sort -u to remove duplicates:

git log --name-only --format='' --grep "${ISSUE_NUM?}" | sort -u
Related