Git log tabular formatting

git log format
git shortlog
git log pretty=format author
git log --oneline --graph
git log branch
git log file
git log --author
git format commit message

I have a simple alias to display few last commits:

log --pretty=format:'%h %an %s' -10

How can I make the results to be displayed in columns, like this:

898e8789 Author1             Commit message here
803e8759 Other Author name   Commit message here

In Git 1.8.3 and later, there is native support for this in the pretty format, using the %<(N) syntax to format the next placeholder as N columns wide:

$ git log --pretty=format:'%h %<(20)%an %s' -10

For versions before 1.8.3, the previous version of this answer, retained below, should work.

Here's a solution in Bash using read to parse the log lines back apart, and printf to print them out, with a fixed width field for the authors name so the columns will stay lined up. It assumes that | will never appear in the author's name; you can choose another delimiter if you think that might be a problem.

git log --pretty=format:'%h|%an|%s' -10 | 
  while IFS='|' read hash author message
  do 
    printf '%s %-20s %s\n' "$hash" "$author" "$message"
  done

You can create this as an alias using:

[alias]
    mylog = "!git log --pretty=format:'%h|%an|%s' -10 | while IFS='|' read hash author message; do printf '%s %-20s %s\n' \"$hash\" \"$author\" \"$message\"; done"

I'm sure you could do this in fewer characters using awk but as the saying goes,

Whenever faced with a problem, some people say "Lets use AWK." Now, they have two problems.

Of course, having said that, I had to figure out how to do it in awk which is a bit shorter:

git ... | awk -F '|' '{ printf "%s %-20s %s\n", $1, $2, $3 }'

Git log format string cheatsheet, Commit Formatting. --pretty[=<format>]; --format=<format>. Pretty-print the contents of the commit logs in� Note that this format affects the way commits are displayed, but not the way the diff is shown e.g. with git log --raw. To get full object names in a raw diff format, use --no-abbrev . format:<string>

You can also do:

git log --pretty=format:'%h %<(20)%an %s' -10

No need for shell magic or post processing with awk, column etc.

git-log Documentation, If the commit is a merge, and if the pretty-format is not oneline, email or raw, way commits are displayed, but not the way the diff is shown e.g. with git log --raw . This is the default for git log, git show and git whatchanged commands when there is no --pretty, --format, or --oneline option given on the command line. By default, the notes shown are from the notes refs listed in the core.notesRef and notes.displayRef variables (or corresponding environment overrides).

The following command will print the log in a tabular form

git log --pretty=format:'%h|%an|%s' -10 | column -t -s '|'

the column command "columnates" the output, using the "|" as field separator, it will find out the optimal column width given the input, so it would work well even if you have more fields.

On Linux it will work ok as long as you don't use colors, the Linux implementation doesn't handle well the ANSI escape codes.

But in Mac OS X, it will handle colors and you can use any unicode character as field delimiter. I use ∑ since I'm pretty sure it won't occur by chance on the commit text. | is a bad choice because it could appear in the commit description and also if you use --graph --decorate --all it will appear as part of the symbols used to draw the graph

pretty-formats Documentation, The most basic and powerful tool to do this is the git log command. These examples use a very simple Table 1. Useful specifiers for git log --pretty=format � Log format Pretty format git log --pretty="format:%H" See the next tables on format variables. Hash Commit

In order to get truly tabular format you need to also truncate usernames that are longer than e.g. 20 characters:

git log --pretty=format:'%h %<(20,trunc)%an %s' -10

Additionally, if you're outputting to the terminal, you may want to prevent line overflows by either truncating the commit message field:

git log --pretty=format:'%h %<(20,trunc)%an %<(39,trunc)%s' -10

or wrapping the lines and indenting any overflowing lines to align:

git log --pretty=format:'%w(79, 0, 29)%h %<(20,trunc)%an %s' -10

EDIT: The above example hard-codes the terminal width to be 79 characters. On POSIX systems you can use tput cols to return the width:

git log --pretty=format:'%w(`tput cols`, 0, 29)%h %<(20,trunc)%an %s' -10

or

git log --pretty=format:'%w($((`tput cols`-1)), 0, 29)%h %<(20,trunc)%an %s' -10

Unfortunately these last two break git alias so it will require a terminal alias (unless you really love typing).

Viewing the Commit History, Commit Formatting. 1.1 Pretty-print the output contents in a given format. Syntax: git log --pretty[=<format>]. where� Table 3. Options to limit the output of git log; Option Description-<n> Show only the last n commits--since, --after. Limit the commits to those made after the specified date.--until, --before. Limit the commits to those made before the specified date.--author. Only show commits in which the author entry matches the specified string.--committer

Use Git log to format the commit history, Formatting Log Output. First, this article will take a look at the many ways in which git log 's output can be formatted. Most of� git log--pretty = format: "%B on %ad with hash %h by %an"--date = short That was a bit on how we can use Git log, and specifically on how to format the output. Leave your comments, questions, and doubts in the comment section in case you need to reach me.

Advanced Git Log, git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold� Now you can feed it with almost any git log command and don't have to adapt the code anymore. Try it! How it works? define your git log commands in your .gitconfig as always; define a positive tree column number (optional), where the git graph is shown; Then just call. git tably YourLogAlias. or. git tably YourLogAlias TreeColNumber

A better git log (Example), The git log command displays all of the commits in a repository's history ( optionally in a prettified format), the following command can be used. So with that, we come to an end of this Git log format history blog, I hope you found it informative. In this post, we learned some formatting techniques that print the project information in a more customized and user-friendly way.

Git Log Command Explained, Formatting Log Output. First, this article will take a look at the many ways in which git log 's output can be formatted. Most of these� I keep it simple with git log --oneline --decorate --graph This shows each commit on one line, decorates each line with any information about branches and repos and displays a graph where commits have branched or merged.

Comments
  • If there's a canned Unix utility to do this I'd love to know about it! The best thing I can think of is Perl formatted output, which is a pain.
  • @Zack: man column is your friend.
  • That appears to be a BSDism, unfortunately.
  • it's in the util-linux package.
  • While this works - using the native git-log method as Suggested by @Jesse is much neater
  • @SeanBurlington When I wrote this answer in 2010, that did not exist; support for the spacing placeholders was added in 1.8.3, in 2013 (though for some reason, it seems to be missing from the release notes). Now that you have pointed out that there is a better solution available, I've incorporated that into my answer.
  • I hoped that the %<(N) syntax would work in other areas of Git where --format is used, but it seems to be limited to --pretty for now. In 2013 there was some discussion about using that syntax with for-each-ref --format and some experimentation with %(...:aligned) but that discussion seems to have died.
  • Is there any way to apply the fixed size to the graph as well? And to also truncate fields longer than the specified size? I'm trying to make a log with fixed positions for everything, as that's easier on the eyes.
  • note that for for-each-ref you can use %(align:width=20,position=left) in the formatting, see git-scm.com/docs/git-for-each-ref
  • This seems like the best solution by far to me. Where did you find docs on the %<(20) syntax?
  • It's referenced in the git help log docs, under the PRETTY FORMATS section (I'm using git version 1.8.3.4).
  • This is the shortest yet most accurate answer. Don't need anything else, just built-in git log.
  • This is a new option in 1.8.3, so if you're using 1.8.3 or later, this is definitely a better solution. I've incorporated this suggestion into my answer, as it is on top due to being accepted and thus more likely to be the first thing people see when coming here.