0
0
Gitdevops~5 mins

git log formatting options - Commands & Configuration

Choose your learning style9 modes available
Introduction
Git keeps track of all changes in your project. Sometimes, you want to see these changes in a way that is easy to read or fits your needs. Git log formatting options help you change how the history looks on your screen.
When you want to see a simple list of commit messages without extra details.
When you need to check who made a change and when, in a clear format.
When you want to see the commit history as one line per commit for quick scanning.
When you want to include the commit hash, author, date, and message in a custom style.
When you want to export commit history in a format easy to read or use in reports.
Commands
Shows the commit history with each commit on one line, displaying a short commit hash and the commit message. This makes it easy to scan recent changes quickly.
Terminal
git log --oneline
Expected OutputExpected
a1b2c3d Fix typo in README 4e5f6g7 Add user login feature 8h9i0j1 Initial commit
--oneline - Show each commit as one line with short hash and message
Displays the commit history with a custom format: short hash, author name, relative date, and commit message. This helps you see who made changes and when in a friendly way.
Terminal
git log --pretty=format:"%h - %an, %ar : %s"
Expected OutputExpected
a1b2c3d - Alice, 2 hours ago : Fix typo in README 4e5f6g7 - Bob, 1 day ago : Add user login feature 8h9i0j1 - Alice, 3 days ago : Initial commit
--pretty=format:"%h - %an, %ar : %s" - Customize the output format of git log
Shows the commit history as a graph with branches and merges, using one line per commit and showing branch names or tags. This helps visualize the project history.
Terminal
git log --graph --oneline --decorate
Expected OutputExpected
* a1b2c3d (HEAD -> main) Fix typo in README * 4e5f6g7 Add user login feature | * 9k8l7m6 (feature) Start new feature |/ * 8h9i0j1 Initial commit
--graph - Show commit history as a text graph
--decorate - Show branch and tag names
--oneline - Show each commit on one line
Key Concept

If you remember nothing else from git log formatting, remember: you can change how commit history looks to make it easier to read and understand.

Common Mistakes
Using git log without formatting and getting too much information.
The default output can be overwhelming and hard to scan quickly.
Use options like --oneline or --pretty=format to simplify the view.
Incorrectly typing the format string with missing quotes or wrong placeholders.
Git will show errors or unexpected output if the format string is wrong.
Always enclose the format string in double quotes and use valid placeholders like %h, %an, %ar, %s.
Summary
Use git log --oneline to see a simple list of commits with short hashes.
Use git log --pretty=format to customize what details you see for each commit.
Use git log --graph --decorate --oneline to visualize branches and merges in a compact way.