How to output git log with the first line only?

GitVersion ControlFormattingLoggingCommit Message

Git Problem Overview


I am trying to customize the format for git log. I want all commits to be shown in one line. Each line should only show the first line of the commit message.
I found out that git log --pretty=short should do the trick but on my computer it shows the full log as git log does (besides the time stamp).

Further, I tried to use the placeholders as defined in the man page. Though, I could not find a command to shorten the log message. I tried this line git log --pretty=format:'%h : %s' which shows the shorted hash %hand the full message %s in one line.

I am using git version 1.7.3.1.msysgit.0 on Vista.


Maybe it has something to do with the way I write my commit messages. Here is an example:

Added some functionality.
+ Added print function in Foo class.
+ Added conversion from foo to baz.

So, with the example given I only want to be output Added some functionality. prepended by the shortend hash.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

Does git log --oneline do what you want?

Solution 3 - Git

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

git log --pretty=format:%s

Solution 4 - Git

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"

Output

git lg

Output changed lines

git lg -p

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

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

Further Reading.
https://coderwall.com/p/euwpig/a-better-git-log
Advanced Reading.
http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/

Solution 5 - Git

You can define a global alias so you can invoke a short log in a more comfortable way:

git config --global alias.slog "log --pretty=oneline --abbrev-commit"

Then you can call it using git slog (it even works with autocompletion if you have it enabled).

Solution 6 - Git

Without commit messages, only the hash:

git log --pretty=oneline | awk '{print $1}'

Solution 7 - Git

if you only want the first line of the messages (the subject):

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

and if you want all the messages on this branch going back to master:

git log --pretty=format:"%s" master..HEAD

Last but not least, if you want to add little bullets for quick markdown release notes:

git log --pretty=format:"- %s" master..HEAD

Solution 8 - Git

git log --format="%H" -n 1 

Use the above command to get the commitid, hope this helps.

Solution 9 - Git

If you want to print commit-id and commit message only > git log --oneline | awk '{print $1 " " $2}'

Or you can used >git log --oneline

Solution 10 - Git

if you want to always use git log in such way you could add git alias by

git config --global alias.log log --oneline

after that git log will print what normally would be printed by git log --oneline

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJJDView Question on Stackoverflow
Solution 1 - GitGauthierView Answer on Stackoverflow
Solution 2 - Git9000View Answer on Stackoverflow
Solution 3 - GittechnophyleView Answer on Stackoverflow
Solution 4 - GitatilkanView Answer on Stackoverflow
Solution 5 - GitThat Brazilian GuyView Answer on Stackoverflow
Solution 6 - Gitotiai10View Answer on Stackoverflow
Solution 7 - GitgMaleView Answer on Stackoverflow
Solution 8 - Gituser2853343View Answer on Stackoverflow
Solution 9 - GitEng_FarghlyView Answer on Stackoverflow
Solution 10 - GitnoisyView Answer on Stackoverflow