Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output git log with the first line only?

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.

like image 706
JJD Avatar asked Dec 18 '10 17:12

JJD


People also ask

How do I limit a git log?

The most basic filtering option for git log is to limit the number of commits that are displayed. When you're only interested in the last few commits, this saves you the trouble of viewing all the commits in a page. You can limit git log 's output by including the - option.

What is git log -- Oneline?

Git Log OnelineThe oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message. It will be used as follows: $ git log --oneline.

How do I search for a string in git log?

Git Browsing the history Searching commit string in git logWill search for removed file string in all logs in all branches. Starting from git 2.4+, the search can be inverted using the --invert-grep option.

Does git log show all branches?

Graph all git branchesDevelopers can see all branches in the graph with the –all switch. Also, in most situations, the –decorate switch will provide all the supplemental information in a formatted and nicely color-coded way.


1 Answers

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.

like image 119
Gauthier Avatar answered Oct 10 '22 09:10

Gauthier