How to output git log with the first line only?

Does git log --oneline do what you want?

Have you tried this?

git log --oneline 

It's an alias for git log --pretty=oneline --abbrev-commit, and displays the "short sha" and "short description", for example:

9bee8857 Write more code
831fdd6e Write some code Second line of message

The problem is that you are missing an empty line after the first line of your commit message. The command above usually works for me, but I just tested on a commit without empty second line. I got the same result as you: the whole message on one line.

Empty second line is a standard in git commit messages. The behaviour you see was probably implemented on purpose.

The first line of a commit message is meant to be a short description. If you cannot make it in a single line you can use several, but git considers everything before the first empty line to be the "short description". oneline prints the whole short description, so all your 3 rows.

Better and easier git log by making an alias. Paste the code below to terminal just once for one session. Paste the code to zshrc or bash profile to make it persistant.

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"


git lg

Output changed lines

git lg -p

Alternatively (recommended)
Paste this code to global .gitconfig file

  lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

Further Reading.
Advanced Reading.

If you need no hashes and just the first lines (subject lines):

git log --pretty=format:%s