Reputation: 7803
I'm writing a script to analyze changes have been made into a git repo. At some point I need to iterate over all the commits and obtain these information about each of them:
I get the commit messages and dates by git log
. The issue I have is with the files.
If I don't want to collect number of lines added/removed, I'd simply use
git diff-tree --no-commit-id --name-status -M -r abcd12345
The output would be something like
A Readme.md
M src/something.js
D src/somethingelse.js
R100 tests/a/file.js tests/b/file.js
Which I can parse and read programmatically.
To get information about lines added/removed, I could use this:
git diff-tree -M -r --numstat abcd12345
The output would be like:
abcd12345
82 0 Readme.md
41 98 src/something.js
0 64 src/somethingelse.js
0 0 tests/{a => b}/file.js
Which is not that machine readable for renamed files.
My question is: Is there any way to combine these two commands? It seems I can't use --numstat
with --name-status
.
I can run two separate command and merge the result in my script as well. In that case, is there any other switches that I can use to make the result of the second command more machine readable?
Thanks.
Upvotes: 5
Views: 1072
Reputation: 487755
I think your analysis (that you need two separate commands) is correct. Use -z
to obtain machine-readable output with --numstat
(this disables both fancy rename encoding and all special-character-quoting), but note that you will then have to break lines apart at ASCII NULs instead of newlines.
Upvotes: 4