← Back to Chapters

Git History

? Git History

? Quick Overview

Git History allows you to explore how a project has evolved over time by examining commits, messages, authors, and changes. It helps track progress, debug issues, and understand collaboration flow.

? Key Concepts

  • Commits represent snapshots of your project
  • Each commit has a unique hash
  • Git history is branch-aware
  • Logs can be filtered, searched, and visualized

? Syntax & Theory

The primary command for inspecting history is git log. It provides chronological details of commits starting from the most recent.

? Code Examples

? View Code Example
// Show complete commit history
git log
? View Code Example
// Limit history to last 5 commits
git log -5
? View Code Example
// View history with branch graph
git log --graph --oneline
? View Code Example
// Search commit messages containing keyword
git log --grep="authentication"
? View Code Example
// Show changes introduced in a specific commit
git show <commit-hash>
? View Code Example
// Checkout a previous commit temporarily
git checkout <commit-hash>
? View Code Example
// View history of a specific file
git log <file-name>

? Live Output / Explanation

The output of Git history commands includes commit hashes, authors, timestamps, and messages. Graph mode visually shows branch merges, making collaboration easier to understand.

? Interactive Example

Try running git log --graph --oneline --all in a repository with multiple branches to visually explore how branches diverge and merge.

?️ Use Cases

  • Auditing project changes
  • Debugging regressions
  • Understanding team contributions
  • Reviewing feature evolution

? Tips & Best Practices

  • Write clear, descriptive commit messages
  • Use --oneline for readability
  • Inspect commits before reverting

? Try It Yourself

  • Run git log in any repository
  • Search commits using --grep
  • Inspect changes with git show
  • Checkout an older commit and return back