Search code examples
gitformat

How can I get git log to print the full hash and short stats of each commit on one line?


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?


Solution

  • 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 or git log --pretty=oneline (as mentioned by ks1322)
    Note that when using --pretty, %h is the short hash code, and %H is the true hash code. (as mentioned by mike-pomax-kamermans)

    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.