0
0
Gitdevops~5 mins

Viewing commit history with git log - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you want to see what changes were made in your project over time. The git log command shows a list of past changes, called commits, so you can understand the history of your work.
When you want to check who made a change and when in your project
When you need to find a specific change to fix a bug
When you want to review the history before merging branches
When you want to see the messages describing past changes
When you want to track progress or understand the development timeline
Commands
This command shows a simple list of commits with their short IDs and messages, making it easy to scan the history quickly.
Terminal
git log --oneline
Expected OutputExpected
abc1234 Fix typo in README def5678 Add user login feature 789abcd Initial commit
--oneline - Shows each commit in one line with short ID and message
This command shows the detailed changes (diffs) for the last two commits, helping you see exactly what was added or removed.
Terminal
git log -p -2
Expected OutputExpected
commit abc1234 Author: Jane Doe <jane@example.com> Date: Tue Apr 23 10:00 2024 +0000 Fix typo in README diff --git a/README.md b/README.md index e69de29..d95f3ad 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -Hello Wrold +Hello World +Added greeting line commit def5678 Author: John Smith <john@example.com> Date: Mon Apr 22 09:30 2024 +0000 Add user login feature (diff output continues...)
-p - Shows the patch (diff) introduced in each commit
-2 - Limits output to the last two commits
This command shows a visual graph of all branches and commits with labels, making it easier to understand branching and merging.
Terminal
git log --graph --decorate --all --oneline
Expected OutputExpected
* abc1234 (HEAD -> main) Fix typo in README * def5678 (origin/main) Add user login feature * 789abcd Initial commit
--graph - Draws a text-based graph of the commit history
--decorate - Shows branch and tag names next to commits
--all - Shows commits from all branches
--oneline - Shows each commit in one line
Key Concept

If you remember nothing else from this pattern, remember: git log shows your project's history so you can understand what changed and when.

Common Mistakes
Running git log without any flags and getting too much information
The default output can be long and hard to read for beginners
Use flags like --oneline or -2 to limit and simplify the output
Expecting git log to show file contents instead of commit history
git log only shows commit metadata and messages, not file contents
Use git show or git diff to see file changes
Summary
Use git log to see the history of commits in your project.
Flags like --oneline and -p help simplify or detail the output.
The --graph and --decorate flags help visualize branches and labels.