How to Show Git History One Line per Commit with git log --oneline
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
git log --oneline [-n <number>] [-- <file>]
| Part | What it means |
|---|---|
git log | Shows the commits, newest first |
--oneline | One 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 --versionto see which one you have; this guide uses Git 2.56.1.
Step 1: See the Full History
In the repository's folder:
git log
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

Four commits take 23 lines. Each starts with commit and its full hash, 40 characters long.
Step 2: Show One Line per Commit
git log --oneline
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 same four commits, one line each:
5e618aeis 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 themainbranch, at its newest commit.Add a shopping listis 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
git log --oneline -n 2
5e618ae (HEAD -> main) Add a shopping list
4dd00b7 Use less sugar in the pancakes

-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
git log --oneline -- pancakes.md
4dd00b7 Use less sugar in the pancakes
dac284a Add the pancake recipe

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:
git log --oneline pancakes.md
4dd00b7 Use less sugar in the pancakes
dac284a Add the pancake recipe
Now make a typo, pancake.md instead of pancakes.md, first without --:
git log --oneline pancake.md
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:
git log --oneline -- pancake.md

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
| Mistake | What happens | Do this instead |
|---|---|---|
A typo in the file name after -- | No output at all, and no error | Check the name with ls |
Leaving out -- before a file name | It works, until the name is wrong: then Git stops with fatal: ambiguous argument | Always write -- before file names |
| Expecting the same hashes as this guide | Your hashes differ | Use the hashes your own git log --oneline prints |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
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 yet | The repository has no commits | Make a first commit |
FAQ
Can I see the full hash on one line?
Yes, with --pretty=oneline, the same format without the shortened hash:
git log --pretty=oneline
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.
