0
0
GitHow-ToBeginner · 3 min read

How to Use git log --oneline for Simple Commit History

Use git log --oneline to see a compact list of commits where each commit is shown in one line with its short hash and message. This command helps you quickly review your project's commit history in a simple, readable format.
📐

Syntax

The basic syntax of the command is:

  • git log: Shows the commit history.
  • --oneline: Displays each commit in a single line with a short hash and commit message.
bash
git log --oneline
💻

Example

This example shows how to use git log --oneline to get a brief view of recent commits:

bash
git log --oneline
Output
a1b2c3d Fix typo in README 4e5f6g7 Add new feature 8h9i0j1 Initial commit
⚠️

Common Pitfalls

Some common mistakes when using git log --oneline include:

  • Forgetting the double dash -- before oneline, which causes an error.
  • Expecting detailed commit info; --oneline shows only short hashes and messages.
  • Not combining with other options like -n to limit the number of commits shown.

Correct usage example:

bash
git log --oneline -n 3
Output
a1b2c3d Fix typo in README 4e5f6g7 Add new feature 8h9i0j1 Initial commit
📊

Quick Reference

Here is a quick cheat sheet for git log --oneline usage:

CommandDescription
git log --onelineShow commits in one line each with short hash and message
git log --oneline -n 5Show last 5 commits in one line each
git log --oneline --graphShow commits with a simple graph and one line each
git log --oneline --author="name"Show commits by a specific author in one line each

Key Takeaways

Use git log --oneline to see a simple, one-line summary of each commit.
Always include the double dash -- before oneline to avoid errors.
Combine --oneline with other options like -n to limit output.
This command is great for quickly scanning commit history without details.
For more detail, use git log without --oneline.