I want to get all files that are changed in commits that matched some conditions. So I have following: git log --grep=123
, and I need to get files that are changed in that commits as an aggregated list, e.g. if file is changed in several commits it should be included only once in the resulting list. That is like selecting several commits in tortoise svn log window, it lists all files that are changed in the selected commits
Asked
Active
Viewed 4,386 times
9

michael nesterenko
- 14,222
- 25
- 114
- 182
2 Answers
11
git log
shouldn't be used for scripting, but here's a quick solution:
git log --grep=pattern --name-only --pretty=format:'' | sort -u

knittl
- 246,190
- 53
- 318
- 364
-
1why `git log` should not be used in scripting? – michael nesterenko Feb 16 '12 at 16:37
-
3Because it's a so-called porcelain command, intended for human user consumption, whereas plumbing commands are provided for machine consumption (scripting). To properly write the above line, one should use `git rev-list` and `git diff-tree` or something … – knittl Feb 16 '12 at 16:40
-
@knittl: I don't entirely agree with that. `git-log` is quite reasonable to use for scripting *if you control the output format carefully*, in the same way that `git status` is bad but `git status --porcelain` is good. Would you really suggest running `git rev-list ...` and looping over it with `git show --format=...` instead of simply using `git log ... --format=...`? – Cascabel Feb 16 '12 at 17:08
-
`git show` is also porcelain ;) but yeah, for this task `git log` is probably good enough – knittl Feb 16 '12 at 17:16
-
_Because it's a so-called porcelain command, intended for human user consumption_ – the output of `man git-status` describes `--porcelain[=
]` option as _Give the output in an easy-to-parse format **for scripts**._ which gives the _porcelain_ word the exact opposite meaning. – Piotr Dobrogost Aug 27 '21 at 15:19 -
@PiotrDobrogost Good point. Unfortunately, Git's UI is not 100% consistent and sometimes confusing. I think [this answer to "What does 'porcelain' mean in Git"](https://stackoverflow.com/a/6978402/112968) explains it pretty well. – knittl Aug 27 '21 at 15:33
5
Not exactly the answer but if your condition is position of start and end of consistent commits series git is ready to help:
git diff --name-only <SHA, tag start> <SHA, tag end>

I159
- 29,741
- 31
- 97
- 132