reljicb
reljicb

Reputation: 91

git log does not start from the first line in Mac terminal

I'm executing the following command in the Mac Terminal window:

git log --pretty=format:'%s'

The problem is when there are commits in the output whose subject/title is long enough so it is wrapped by the Terminal in several lines, the first page of the output does not start from the first line of output (of the most recent commit), but the listing is scrolled down by that many lines how many times I had line wrapping. This forces always to use my mouse to scroll up to see the head of the output, which is extremely impractical.

Here's an example in case I was not sufficiently clear. When I execute the above command the output should be something like this:

# a commit with a veryyyyy looooon title blah blah blah whi
ch wraps into a new line
# third commit with a veryyyyy looooon title blah blah blah which al
so wraps into a second line
# 1st commit with a title of a normal length that I see
# 2nd a commit with a title of a normal length
# 3rd a commit with a title of a normal length
# 4th commit with a title of a normal length
# fourth commit with a veryyyyy looooon title blah blah blah which a
lso wraps into a new line
# 5th commit with a title of a normal length
# 6th commit with a title of a normal length
# one more commit with a veryyyyy looooon title blah blah blah whi
ch also wraps into a new line
# 7th commit with a title of a normal length
# 8th commit with a title of a normal length
...
# 49th commit with a title of a normal length
# 50th commit with a title of a normal length
:

Notice: It is normal to expect that output could be wrapped, in case my Terminal window is not very wide, and it should wait for me to scroll to the next line, as there are more commits than it can fit into the Terminal window height.

However, this is not what I see in terminal window. The first commit that I see in the output is the one with the title: "# 1st commit with a title of a normal length". The first 2 commits are out of the view, because they span into 4 lines, and I had 4 commits in the output in total that are wrapped into 2 lines. If I want to see the real first commit ("# a commit with a veryyyyy looooon...") in the output, I have to grab the mouse and scroll a few lines up.

BTW, this has nothing to do with --pretty=format switch, as the similar behaviour happens with plain "git log". I just used pretty formatted output to simplify the illustration of the problem.

I don't know if this is the problem of git formatting, or the terminal. Can someone please suggest a solution.

Cheers!

SOLUTION:

Run any git command with -c 'core.pager=less -SFR' switch, like in my example:

git -c 'core.pager=less -SFR' log --pretty=format:'%s'

Upvotes: 3

Views: 949

Answers (1)

VonC
VonC

Reputation: 1323115

Whenever you have a line output issue, you can try some pager option with less.

One way to quickly experiment is to set that option just for the current git command, with "git -c":

git -c 'core.pager=less -SFR' log...

If that is working you can set it for the current repo

git config core.pager 'less -SFR'

Or for all repos:

git config --global core.pager 'less -SFR'

Upvotes: 3

Related Questions