elaichi
elaichi

Reputation: 508

parseable git log output

You can customize the output of git log using --pretty and you can show the number of added and deleted lines using --numstat. It looks like this:

$ git log --pretty=format:"%h - %ar : %s" --numstat config*.ini

f665c63 - 6 months ago : fixes session end post
1       1       config.ini

4541de2 - 7 months ago : fixes missing strings
6       1       config.ini
3       1       config_office.ini

But what I want is the output of both, the commit information and the changes in the files, to show in one line each. Something like this:

1       1       config.ini            f665c63 - 6 months ago : fixes session end post
6       1       config.ini            4541de2 - 7 months ago : fixes missing strings
3       1       config_office.ini     4541de2 - 7 months ago : fixes missing strings

This way it would be straightforward to parse this output using grep, sort, etc. Does git already provide this functionality?

Upvotes: 2

Views: 699

Answers (1)

Jamey Sharp
Jamey Sharp

Reputation: 8511

As far as I can tell, git log can't do that natively. However, this sed command will do it:

sed '/^[0-9]\+\t[0-9]\+\t[^\t]\+$/ b file; h; d; : file; G; s/\n/\t/'

It looks for the --numstat lines. Any non-numstat line is copied into the hold buffer and not printed. Lines with numstat output get the current contents of the hold buffer appended, leaving a newline in the middle, which is then replaced with a tab.

Upvotes: 1

Related Questions