[git] 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.

This question is related to git version-control formatting logging commit-message

The answer is


If you don't want hashes and just the first lines (subject lines):

git log --pretty=format:%s

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

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


Does git log --oneline do what you want?


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/


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


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).


Without commit messages, only the hash:

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

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

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to version-control

How can I switch to another branch in git? Do I commit the package-lock.json file created by npm 5? Project vs Repository in GitHub Remove a modified file from pull request Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: How to squash all commits on branch git: updates were rejected because the remote contains work that you do not have locally Sourcetree - undo unpushed commits Cannot checkout, file is unmerged Git diff between current branch and master but not including unmerged master commits

Examples related to formatting

How to add empty spaces into MD markdown readme on GitHub? VBA: Convert Text to Number How to change indentation in Visual Studio Code? How do you change the formatting options in Visual Studio Code? (Excel) Conditional Formatting based on Adjacent Cell Value 80-characters / right margin line in Sublime Text 3 Format certain floating dataframe columns into percentage in pandas Format JavaScript date as yyyy-mm-dd AngularJS format JSON string output converting multiple columns from character to numeric format in r

Examples related to logging

How to redirect docker container logs to a single file? Console logging for react? Hide strange unwanted Xcode logs Where are logs located? Retrieve last 100 lines logs Spring Boot - How to log all requests and responses with exceptions in single place? How do I get logs from all pods of a Kubernetes replication controller? Where is the Docker daemon log? How to log SQL statements in Spring Boot? How to do logging in React Native?

Examples related to commit-message

How to output git log with the first line only? Should I use past or present tense in git commit messages? Print commit message of a given commit in git How do I make Git use the editor of my choice for commits? How to edit incorrect commit message in Mercurial? How do I edit an incorrect commit message in git ( that I've pushed )?