Git Log One Line

📜Part of the Git and Windows tooling notes on this site. For the PowerShell side, see the PowerShell Complete Guide.
The short answer

git log --oneline. Add --graph --decorate to see branches, and -n 10 to limit how many commits you get.

The default git log gives you six lines per commit. That is fine for reading one commit and useless for getting your bearings in a repository. The one-line form is what most people actually want, and there are a few variations worth knowing.

The One-Line Log

git log --oneline

That gives you one commit per line: an abbreviated hash, then the subject line of the commit message.

9526824 Fix pagination on the reports page
4ec32b0 Add retry handling to the import job
7847658 Bump dependencies
e89dc19 Correct the totals in the monthly summary

--oneline is shorthand. The long form is --pretty=oneline --abbrev-commit, and the two produce identical output. Worth knowing because --pretty=oneline on its own prints the full 40-character hash, which is almost never what you want.

Limiting How Many Commits

An unbounded log opens a pager and you have to quit out of it. Cap it:

git log --oneline -n 10      # last 10 commits
git log --oneline -10       # the same thing, shorter

Adding The Branch Graph

This is the version worth putting in an alias. It draws the branch structure down the left and labels branches and tags.

git log --oneline --graph --decorate --all
* 9526824 (HEAD -> main) Fix pagination on the reports page
* 4ec32b0 Add retry handling to the import job
| * 1a2b3c4 (feature/search) Start the search index
|/
* 7847658 Bump dependencies

--graph draws the lines, --decorate adds the (HEAD -> main) labels, and --all includes branches other than the one you are on. Without --all you only see the history behind your current branch, which hides exactly the branches you were trying to look at.

Making It An Alias

Typing that every time gets old. Save it once:

git config --global alias.lg "log --oneline --graph --decorate --all"

Then git lg does the lot. Drop --global to set it for one repository only. To check what an alias expands to, run git config --get alias.lg, and to remove it, git config --global --unset alias.lg.

Adding Dates And Authors

--oneline deliberately omits both. If you want them, build the format yourself:

git log --pretty=format:'%h %ad %an %s' --date=short
9526824 2026-08-24 A. Developer Fix pagination on the reports page
4ec32b0 2026-08-23 R. Maintainer Add retry handling to the import job

The placeholders are %h abbreviated hash, %ad author date, %an author name and %s subject. --date=short gives you YYYY-MM-DD instead of the full timestamp. Swap in --date=relative for “3 days ago” style output.

--pretty=format: and --pretty=oneline are different things. The first takes your format string. The second is a built-in preset that ignores it. If your custom format seems to be having no effect, check you have not written --pretty=oneline out of habit.

Filtering The One-Line Log

The one-line format combines with every filter git log has:

git log --oneline --since="2 weeks ago"
git log --oneline --author="Sam"
git log --oneline --grep="pagination"          # search commit messages
git log --oneline -S"functionName"             # commits that changed this string
git log --oneline -- path/to/file              # history of one file

-S is the one people do not know about. It finds commits where the number of occurrences of that string changed, so it answers “when was this function added or removed” rather than “which commit messages mention it”.

Filtering by author has a trap of its own, covered in git log by author.

If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for SQL Server?

This site started as a SQL Server blog in 2017 and the archive is still here. The new SQL Server writing, and all the scripts, moved to a site of their own.

sqldba.blogScripts, error library, wait types, SSMS
Browse by topic