Changing the Display of Git Log


This week I’ve been learning git (about which I’m now a believer). I’m moderately savvy with the OSX terminal, but I’ve had to do a bit of spelunking in configuration files–which offer something of a learning curve. This post documents the solution to a small problem that seemed, at first, quite difficult to solve with a Google search. I offer the solution here in case someone has a similar question and can more easily find this post. While this might be common knowledge for the advanced git user, I could see it confounding a beginner (read: me).

The Problem

When I would run “git log” to see a history of commits, git would display them on a new screen, rather than inline with the rest of the terminal content. See below:

For ease of reference, I wanted those commits to display inline with the rest of my Terminal content. The problem is that git displays (at least in oh-my-zsh, the shell I’m using) the logfile with less, a Unix file viewing program. You can determine this by looking in title bar of the terminal window. Mine reads “git log -1 – git – less – 72x9”, and the takeaway here is that you can discern a great deal of helpful info from the Terminal title bar (also contained in that string, for example, is “git log -1”, the command I ran to see the most recent commit).

So my question was: How can I tell git (or oh-my-zsh) to stop displaying the git log in less and instead display the log content inline? Complicating the process was the fact that I didn’t know if this was a git configuration issue or a zsh configuration issue.

The solution

The key term I was missing is “pager”, which I found via this stack exchange conversation. As noted there, I can display the log content outside of less with the following command:

git --no-pager log -1

which yields the following output:

And the following command tells git (by editing .gitconfig) to default to a pager-free display:

git config --global core.pager cat

Again, a solution that was easy to find on stackoverflow–once I had acquired the proper vocabulary.

« Design and Creativity Using Textmate and Markdown with Evernote: Configuring a Workflow »

Comments