Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Git log with short stat in one line?

Following command outputs following lines of text on console

git log --pretty=format:"%h;%ai;%s" --shortstat ed6e0ab;2014-01-07 16:32:39 +0530;Foo  3 files changed, 14 insertions(+), 13 deletions(-)  cdfbb10;2014-01-07 14:59:48 +0530;Bar  1 file changed, 21 insertions(+)  5fde3e1;2014-01-06 17:26:40 +0530;Merge Baz 772b277;2014-01-06 17:09:42 +0530;Qux  7 files changed, 72 insertions(+), 7 deletions(-) 

I'm interested in having above format to be displayed like this

ed6e0ab;2014-01-07 16:32:39 +0530;Foo;3;14;13 cdfbb10;2014-01-07 14:59:48 +0530;Bar;1;21;0 5fde3e1;2014-01-06 17:26:40 +0530;Merge Baz;0;0;0 772b277;2014-01-06 17:09:42 +0530;Qux;7;72;7 

This will be consumed in some report which can parse semicolon separated values. The thing is the text "\n 3 files changed, 14 insertions(+), 13 deletions(-)" (new line included) gets converted to 3;14;13 (without new line) One possible corner case is text like "5fde3e1;2014-01-06 17:26:40 +0530;Merge Baz" which doesn't have such line. In that case I want ;0;0;0

Overall the goal is to analyze file change stats over a period of time. I read the git log documentation but couldn't find any format which will help me to render in this format. The best I came up was the above command mentioned.

So any command or shell script which can generate the expected format would be of great help.

Thanks!

like image 569
Ankush Avatar asked Jan 15 '14 12:01

Ankush


People also ask

How do I limit a git log?

The most basic filtering option for git log is to limit the number of commits that are displayed. When you're only interested in the last few commits, this saves you the trouble of viewing all the commits in a page. You can limit git log 's output by including the - option.

What is git log Oneline?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message. It will be used as follows: $ git log --oneline.

What is skipping in git log?

Skipping is showing because git is using less as a pager by default. less "skips" line when you scroll up or down manually.


1 Answers

git log  --oneline --pretty="@%h"  --stat   |grep -v \| |  tr "\n" " "  |  tr "@" "\n" 

This will show something like this:

a596f1e   1 file changed, 6 insertions(+), 3 deletions(-)  4a9a4a1   1 file changed, 6 deletions(-)  b8325fd   1 file changed, 65 insertions(+), 4 deletions(-)  968ef81   1 file changed, 4 insertions(+), 5 deletions(-)  
like image 157
user2461539 Avatar answered Sep 19 '22 21:09

user2461539