Skip to main content

How to Show Git History One Line per Commit with git log --oneline

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

git log shows every commit with its full hash, its author, its date and its message, at least five lines each. git log --oneline shows one line per commit instead: a short hash and the commit's title, so a whole history fits on one screen.

This guide shows the history of a small repository both ways, with real output from Git 2.56.1.

Syntax​

Syntax
git log --oneline [-n <number>] [-- <file>]
PartWhat it means
git logShows the commits, newest first
--onelineOne line per commit: a short hash and the commit's title, its message's first line
-n <number>Optional. Only the newest <number> commits
-- <file>Optional. Only the commits that changed <file>. The -- tells Git that what follows is a file, not a commit

The git log documentation describes --oneline as a shorthand for --pretty=oneline --abbrev-commit used together: the oneline format, <hash> <title-line>, with the hash shortened.

The Example​

A small repository called recipe-book has four commits on its main branch: a pancake recipe, a soup recipe, a change to the pancakes, and a shopping list.

Prerequisites​

  • Git. Run git --version to see which one you have; this guide uses Git 2.56.1.

Step 1: See the Full History​

In the repository's folder:

Terminal
git log
Output
commit 5e618aefd03075c658d768b7196375879b8c262b (HEAD -> main)
Author: Your Name <you@example.com>
Date: Fri Dec 4 10:52:08 2026 +0000

Add a shopping list

commit 4dd00b7aa9399edb6dd7964842a3b03124e1c83f
Author: Your Name <you@example.com>
Date: Fri Dec 4 10:52:08 2026 +0000

Use less sugar in the pancakes

commit 47164d9df1c1304529ba5673d41a988822efb745
Author: Your Name <you@example.com>
Date: Fri Dec 4 10:52:08 2026 +0000

Add the soup recipe

commit dac284a4befee39c0f9b236f0211012cbf5bc02d
Author: Your Name <you@example.com>
Date: Fri Dec 4 10:52:08 2026 +0000

Add the pancake recipe

The terminal after git log: four commits, each with a 40-character hash, an Author line, a Date line and its message, the newest, Add a shopping list, first.

Four commits take 23 lines. Each starts with commit and its full hash, 40 characters long.

Step 2: Show One Line per Commit​

Terminal
git log --oneline
Output
5e618ae (HEAD -> main) Add a shopping list
4dd00b7 Use less sugar in the pancakes
47164d9 Add the soup recipe
dac284a Add the pancake recipe

The terminal after git log --oneline: four lines, from 5e618ae (HEAD -> main) Add a shopping list down to dac284a Add the pancake recipe.

The same four commits, one line each:

  • 5e618ae is the start of the full hash, 5e618aefd0…: a prefix that no other commit in the repository shares, 7 characters here. The gitrevisions documentation says a commit can be named by its full hash or a leading substring that is unique within the repository, so you can use this short hash wherever Git asks for a commit.
  • (HEAD -> main) marks where you are: on the main branch, at its newest commit.
  • Add a shopping list is the commit's title.

Your hashes will be different, because a hash depends on who made the commit and when.

Step 3: Show Only the Newest Commits​

Terminal
git log --oneline -n 2
Output
5e618ae (HEAD -> main) Add a shopping list
4dd00b7 Use less sugar in the pancakes

The terminal after git log --oneline -n 2, which shows only the two newest commits, 5e618ae and 4dd00b7.

-n 2 stopped after two commits. In a long history, this is the quick way to see what happened last.

Step 4: Show Only the Commits That Changed One File​

Terminal
git log --oneline -- pancakes.md
Output
4dd00b7 Use less sugar in the pancakes
dac284a Add the pancake recipe

The terminal after git log --oneline -- pancakes.md, which shows the two commits that changed the pancake recipe, 4dd00b7 and dac284a.

Only the two commits that changed pancakes.md are left: the one that added it, and the one that changed it.

Step 5: See Why the -- Matters​

The -- looks optional, and with a correct file name it is:

Terminal
git log --oneline pancakes.md
Output
4dd00b7 Use less sugar in the pancakes
dac284a Add the pancake recipe

Now make a typo, pancake.md instead of pancakes.md, first without --:

Terminal
git log --oneline pancake.md
Output
fatal: ambiguous argument 'pancake.md': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Then with it:

Terminal
git log --oneline -- pancake.md

The terminal after three runs: git log --oneline pancakes.md lists two commits, git log --oneline pancake.md fails with fatal: ambiguous argument 'pancake.md': unknown revision or path not in the working tree, and git log --oneline -- pancake.md prints nothing.

Without --, Git couldn't tell whether pancake.md was a commit or a file, found neither, and stopped with an error. With --, Git knew it was a file, found no commits that changed a file by that name, and printed nothing at all, without an error. The documentation says paths may need to be prefixed with -- to separate them from options or the revision range, when confusion arises. So when a file-filtered log is empty, check the file name first.

Common Mistakes​

MistakeWhat happensDo this instead
A typo in the file name after --No output at all, and no errorCheck the name with ls
Leaving out -- before a file nameIt works, until the name is wrong: then Git stops with fatal: ambiguous argumentAlways write -- before file names
Expecting the same hashes as this guideYour hashes differUse the hashes your own git log --oneline prints

Troubleshooting​

SymptomLikely causeFix
fatal: ambiguous argument '…': unknown revision or path not in the working tree.A misspelled file or commit name, without --Fix the name, and put -- before file names
fatal: your current branch 'main' does not have any commits yetThe repository has no commitsMake a first commit

FAQ​

Can I see the full hash on one line?​

Yes, with --pretty=oneline, the same format without the shortened hash:

Terminal
git log --pretty=oneline
Output
5e618aefd03075c658d768b7196375879b8c262b (HEAD -> main) Add a shopping list
4dd00b7aa9399edb6dd7964842a3b03124e1c83f Use less sugar in the pancakes
47164d9df1c1304529ba5673d41a988822efb745 Add the soup recipe
dac284a4befee39c0f9b236f0211012cbf5bc02d Add the pancake recipe

Do these commands work in PowerShell?​

Yes, unchanged, -- included.

Conclusion​

git log --oneline showed the four commits of recipe-book in four lines, each with a short hash and its title, where git log took 23 lines. -n 2 kept the newest two, and -- pancakes.md kept the two that changed the pancake recipe. Write the -- before file names: without it, a typo stops Git with fatal: ambiguous argument; with it, a typo gives an empty list.

Additional Resources​

  • git log: --oneline, -n, paths, and every other option.
  • gitrevisions: the ways to name a commit, short hashes included.