Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git log, is there a way to get '--name-status' and '--numstat' in one command?

Tags:

git

git-log

For all files of a commit, I would like both the status modifier --name-status provides, as well as the amount of added and deleted lines that --numstat gives. Say I have the following:

> git log --pretty=format:"%aN %ct" --reverse --name-status --encoding=UTF-8 --no-renames
John Doe 1234567489
M       foo/bar/foo.bar
A       bar/hello.txt

and:

> git log --pretty=format: --reverse --numstat --encoding=UTF-8 --no-renames
9      5       foo/bar/foo.bar
21     0       bar/hello.txt

Is there a single command/combination of flags which gives me the output of them combined? Something along the lines of this:

John Doe 1234567489
M    9    5       foo/bar/foo.bar
A    21   0       bar/hello.txt

I know it is possible to combine them with some awk magic, but seeing as I will do this on multiple large repositories and performance matters, a single git log command would be preferable.

like image 877
Jos Kraaijeveld Avatar asked Nov 13 '22 09:11

Jos Kraaijeveld


1 Answers

Since --name-status seems to override any other flags (it is similar to --name-only), you could use a combination of --summary and --numstats. However, it will not be on the same line as you have described.

git log --pretty=format:"%aN %ct" --reverse --summary --numstat --encoding=UTF-8 --no-renames

would produce something like:

Christopher Corley 1363309327
4929    0       IEEEtran.cls
22      46      paper.tex
 create mode 100644 IEEEtran.cls

Note that this is only listing the summary of mode changes. For modified files with no mode changes (i.e., 'M'), they will not appear in the summary list.

Similarly, you may find it beneficial to use --raw instead of --summary, which lists modified files:

Christopher Corley 1363309327
:000000 100644 0000000... 5e2d183... A  IEEEtran.cls
:100644 100644 2abed5a... 91f133d... M  paper.tex
4929    0       IEEEtran.cls
22      46      paper.tex
like image 87
Christopher Corley Avatar answered Nov 15 '22 04:11

Christopher Corley