MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Inspecting Commit History with git log and Formatting Flags0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
3.1Inspecting Commit History with git log and Formatting Flags3.2Comparing Changes with git diff (Working Tree vs Staged vs HEAD)3.3Ignoring Unwanted Files and Secrets using .gitignore Rules
HomeTutorialsGit & GitHub BasicsInspecting Commit History with git log and Formatting Flags
Comparing Changes with git diff (Working Tree vs Staged vs HEAD)

Inspecting Commit History with git log and Formatting Flags

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

As software evolves over months and years, inspecting historical commits becomes crucial for tracking features, conducting post-mortems on bugs, and reviewing peer contributions. The git log command is Git's primary time machine.


1. Basic History Inspection: git log

Executing git log lists the commits made in that repository in reverse chronological order (newest commit first):

1git log

Standard Output Format:

1commit 7b3f81e28d4c5a9b0c2d4e6f8a0b1c2d3e4f5a6b (HEAD -> main)
2Author: Sumit Sharma <sumit@mskinstitute.com>
3Date: Mon Sep 15 10:30:00 2026 +0530
4 
5 feat(auth): add JWT token expiration check
6 
7commit 4a2c91d8f1e3a5b7c9d0e2f4a6b8c0d2e4f6a8b0
8Author: Neha Gupta <neha@mskinstitute.com>
9Date: Sun Sep 14 16:15:22 2026 +0530
10 
11 fix(css): fix mobile navbar z-index overflow
Note
[!NOTE] When the log output exceeds your terminal height, Git pages the output using less. - Press Spacebar to scroll down one page. - Press b to scroll up. - Press q to quit and return to the command prompt.

2. Essential Power Flags for git log

A. Compact Single-Line View (--oneline)

Condenses each commit into its short 7-character hash and commit title:

1git log --oneline

Output:

17b3f81e (HEAD -> main) feat(auth): add JWT token expiration check
24a2c91d fix(css): fix mobile navbar z-index overflow
39f1e82b docs: update project README

B. Limit Output Count (-n <number>)

View only the last $N$ commits:

1git log -n 5 --oneline

C. Show Changed Files and Stats (--stat)

Displays the files modified, number of lines inserted (+), and deleted (-):

1git log --stat -n 2

D. Show Full Line-by-Line Code Patches (-p)

Shows the actual line diff introduced by each commit:

1git log -p -n 1

3. Visual Branch Graph (--graph --oneline --all)

When multiple developers are branching and merging, visualizing the branch tree topology directly in your terminal is invaluable:

1git log --graph --oneline --all --decorate

Terminal Output:

1* 7b3f81e (HEAD -> main) Merge branch 'feature-payment'
2|\
3| * 3a89e12 (feature-payment) feat: integrate Stripe checkout API
4| * 2c510fa feat: add webhook listener
5* | 4a2c91d fix: update landing page typography
6|/
7* 9f1e82b Initial commit

Pro Tip: Create an Alias for Visual Log

Save this command permanently as an alias:

1git config --global alias.lg "log --graph --oneline --all --decorate"
2 
3# Now simply run:
4git lg

4. Filtering History

Git lets you filter commit history with precision:

1# 1. Filter by author
2git log --author="Sumit"
3 
4# 2. Filter by date range
5git log --since="2 weeks ago" --until="yesterday"
6 
7# 3. Filter by search keyword in commit messages
8git log --grep="bugfix"
9 
10# 4. Filter history of a specific single file
11git log -p src/utils/auth.js

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the default ordering of commits displayed by git log?
Question 2
Which key allows you to exit the Git log pager and return to the terminal prompt?
Question 3
Which flag formats the output of git log into a clean single-line representation per commit?
Question 4
Which combination of flags renders an ASCII graphical tree of all branches and merge topologies in the terminal?
Question 5
How can you view the commit history for changes that specifically affected only src/db.js?
Next Lesson

Comparing Changes with git diff (Working Tree vs Staged vs HEAD)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Recording Snapshots: git commit and Semantic Commit MessagesComparing Changes with git diff (Working Tree vs Staged vs HEAD)

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext