21

I would like to get this kind of output with git command line:

bcfd649de8850e3bfc9584eb12be8fe136ca6985 3 files changed, 8 insertions(+), 1 deletion(-)

I'm currently using git log --shortstat --reverse --pretty=oneline, but it's actually not a single line and the comment is useless to me:

bcfd649de8850e3bfc9584eb12be8fe136ca6985 Added ActionController#cookies[] as a reader for @cookies that'll return the value of the cookie instead of 
3 files changed, 8 insertions(+), 1 deletions(-)

Is there any way to do it?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
PJ Bergeron
  • 2,788
  • 4
  • 25
  • 42
  • Related: http://stackoverflow.com/questions/21137477/how-to-get-git-log-with-short-stat-in-one-line – jub0bs Mar 14 '15 at 15:10

2 Answers2

21

You can define your own format consisting only of the full hash, and pipe the output of git log to awk (edit: or sed, as proposed by jthill in his comment) in order to replace newlines by spaces where needed (see this):

git log --pretty=tformat:"%H" --shortstat | awk 'ORS=NR%3?" ":"\n"'

or

git log --pretty=tformat:"%H" --shortstat | sed 'N;N;y/\n/ /'

Test

$ git log --pretty=tformat:"%H" --shortstat | awk 'ORS=NR%3?" ":"\n"'
4da27ca5dc8469f19b1524a5dd381aad76f96c69   4 files changed, 26 insertions(+)
60c1e011aadc1bdbf38dde989d0f0497925678d9   4 files changed, 34 insertions(+)
f0e6da70616337f135190dc7f68e22678a7af2ff   4 files changed, 34 insertions(+)
95ea8a002f66a249946a78deb362a2e697dfb80a   4 files changed, 44 insertions(+)
9854efba2301d520bc4fe1a102e102f299ae127d   1 file changed, 2 insertions(+), 2 deletions(-)
c8ee6b36a545c67b2443eea499bf046dd1e2233d   4 files changed, 29 insertions(+)
2d4374edd2d2820f05853b4add9fc5ddba1506ac   4 files changed, 42 insertions(+)
$
Community
  • 1
  • 1
jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • 1
    Or `| sed 'N;N;y/\n/ /'` – jthill Mar 14 '15 at 17:37
  • 2
    This will fail in some cases because some commits don't have stats. When the script hits a "stats-less" commit, the output will break. I found a solution for that on a personal project https://github.com/dreamyguy/gitlogg, and I posted my approach here: http://stackoverflow.com/questions/21137477/how-to-get-git-log-with-short-stat-in-one-line/37497880#37497880 – Wallace Sidhrée May 28 '16 at 10:44
19

For anyone landing here for an answer to "how to get git log one line full commit hash", as I did, there is a flag for the git log which prints the non-abbreviated commit hash.

It's called --no-abbrev-commit. Documentation reads as:

Show the full 40-byte hexadecimal commit object name. This negates --abbrev-commit, either explicit or implied by other options such as "--oneline". It also overrides the log.abbrevCommit variable.

TL;DR: Here is the command for the one-line output with the full commit hash:

git log --oneline --no-abbrev-commit

Note: It has been brought up by an anonymous user that the order of the flags as mentioned above matters since the --oneline makes the --no-abbrev-commit flag meaningful to the git command.

Rojan Gh.
  • 1,062
  • 1
  • 9
  • 32