Viewing History (git log, git status)

🟢 Beginner

📖 Definition

git log is the command used to inspect the repository commit history, displaying a chronological list of saved commits along with their unique SHA hash identifiers, author details, timestamps, and commit messages.

🌐 Multilingual Explanation

English

git log displays commit history in reverse chronological order (newest commits first). Flags like --oneline compress commits into single lines, while --graph --all displays visual branch structures. Commit hashes (40-character SHA strings) uniquely identify every commit in Git history.

Hindi

git log aapke repository ki poori commit history dikhata hai (naye commits sabse upar). --oneline flag har commit ko ek line mein short karke dikhata hai. Har commit ko pehchanne ke liye ek unique SHA Hash ID hoti hai.

Marathi

git log command cha vapar repository madhil zalelya sarv commits chi history pahanyasathi hoto. --oneline mulhe commits chotya format madhye distat. Pratyek commit la ek unique SHA Hash number asto.

Hinglish

Project ka history check karne ke liye terminal mein git log Type karein. --oneline --graph flags se branch history tree format mein saaf dikhti hai. Terminal history view se bahar nikalne ke liye q key press karein.

🤔 Why Do We Use It?

git log allows developers to audit project timelines, verify when specific features were added, track down who wrote a specific commit, and locate commit hashes needed when reverting bugs.

🧠 Simple Explanation

Think of git log like reading a bank account transaction statement. Every entry lists the transaction date, account holder, description, and a unique receipt transaction number (Commit Hash).

📝 Key git log Formatting Flags

# 1. Standard detailed log view
git log

# 2. Compact single-line view (Commit hash + Message)
git log --oneline

# 3. Visual ASCII branch graph view
git log --oneline --graph --all

# 4. Show last N commits only (e.g., last 3 commits)
git log -n 3

# 5. Show file modification statistics per commit
git log --stat

# 6. Show exact line-by-line code patch changes (diffs) per commit
git log -p

# 7. Filter commits by specific author
git log --author="Rahul"

💡 Practical Example

Here is a typical log inspection session in terminal:

# Display compact history
git log --oneline --graph

🔍 Understanding Commit SHA Hashes & HEAD

  • Commit Hash (e.g. a1b2c3d): A unique 40-character hexadecimal string generated by SHA-1 cryptographic hashing algorithm based on commit contents, author, and timestamp. You can reference any commit using its short 7-character prefix.
  • HEAD Pointer: A special pointer in Git that references your current active branch and commit.
HEAD -> refs/heads/main (Current Location)
  │
  ▼
[a1b2c3d] Update README author details
[f9e8d7c] Add project README file
[3c2b1a0] Initial repository commit

👀 Terminal Output

$ git log --oneline --graph --all
* a1b2c3d (HEAD -> main) Update README author details
* f9e8d7c Add project README file
* 3c2b1a0 Initial repository commit

⚠️ Common Mistakes

  • Getting Stuck in Pager View: When git log output exceeds terminal height, Git opens a terminal pager (less). Beginners panic when terminal input seems unresponsive.
    • Fix: Press q key on keyboard to exit pager view back to terminal command prompt! Press Spacebar to page down.
  • Confusing git status and git log:
    • git status: Inspects CURRENT working directory & staging area changes.
    • git log: Inspects PAST permanent commit history records.

🛡️ Safety / Important Notes

  • You can customize git log formatting permanently using Git Aliases (covered in later lessons).
  • Commits listed in git log are permanent and immutable in local repository history.

🌍 Real-World Usage

Software teams use git log --author during code reviews and sprint retrospective meetings to review release history and audit production bug origins.

🧪 Try It Yourself

  1. Open Git Bash or Terminal in your git-practice folder.
  2. Run git log.
  3. Run git log --oneline and notice how clean the compact output looks.

🎯 Mini Challenge

Run git log -n 2 --stat in your terminal and identify how many insertions/deletions occurred in your last 2 commits.

🧭 Navigation

← Home ← Previous: Committing Next: Ignoring Files →