ตัวอย่างบทเรียน

Reading History: log, diff, show and Navigating the Past

Project history isn't just a log—it's documentation of decisions. Learn to read history informatively: filter commits, examine changes between versions, and understand SHA-1 hashes without fear. We'll explore how to distinguish 'good history' from 'garbage history'—this directly impacts how you're perceived in a team.

commit hash git log git diff
คุณจะเรียนรู้อะไรในบทเรียนนี้
  • You'll be able to read repository history and quickly find the right commit by author, date, or keyword.
  • You'll understand how to compare file versions at different levels: working directory, index, and commit.
  • You'll learn to write commit messages following industry-standard conventions (Conventional Commits).

จุดเริ่มต้นของบทเรียน

Commit History as a Project Diary

  • Git log shows history as an inverted diary
  • Each entry is a snapshot of changes
  • Stores who changed what and when
  • Allows you to see code evolution

Imagine that every time you save changes in Git, you're making an entry in a development diary. The 'git log' command shows these entries in reverse chronological order - from newest to oldest. This diary contains the complete project chronology: who made which changes and when. It's not just a list of changes, but a living history of your code's evolution. The ability to read and analyze this history is a key skill for teamwork. After all, it's through commit history that you see how the project developed, what decisions were made and why. Let's take a closer look at the structure of an individual commit.

Reading a Commit: Hash, Author, Date

  • commit: unique hash identifier
  • Author: who made the changes and when
  • Date: commit timestamp
  • Message: what exactly was changed

Look at the output of the 'git log' command. Each entry begins with a long string of characters - this is the commit hash, its unique identifier. To the right, you'll see the author of the changes and when they were made. Below that is the commit message that the developer wrote when saving the changes. Note the format: first comes the author's email in angle brackets, then the timestamp. This data helps understand the context of changes and, if necessary, contact the author for clarification. Now that we've examined the structure of a commit, let's understand what a hash is and why we need it.

#!/bin/bash
cd ~/projects/git-course/
git log -1 --pretty=format:'commit %H%nAuthor: %an <%ae>%nDate:   %ad%n%n    %s'

Commit Hash - Your Key to History

  • A hash is a digital fingerprint of a commit
  • Depends on content and metadata
  • Changing even one character alters the hash
  • Allows precise referencing of any version

A commit hash isn't a random string of characters but the result of a cryptographic function that transforms commit contents into a unique string. If you change even a single byte in the commit, the hash will change completely. This ensures the integrity of the change history. Knowing the hash is like having a precise bookmark - you can reference any version of the code. For example, the 'git checkout' command with a specific hash will take you to the project's state at that commit. This is particularly useful when you need to roll back changes or analyze when a bug was introduced. Now that we understand the structure of history, let's learn how to filter it - because in real projects, there can be thousands of commits.

บทเรียนฉบับเต็มใช้ได้เมื่อสมัครสมาชิก

ฉบับเต็มมีสไลด์เพิ่มอีก 26 สไลด์

วิดีโอ สไลด์ทั้งหมด โน้ต แบบทดสอบ AI ติวเตอร์ และการสัมภาษณ์จะเปิดหลังเข้าสู่ระบบและสมัครสมาชิก

เข้าสู่ระบบหรือลงทะเบียน สมัครสมาชิก

เนื้อหาบทเรียน

  1. Commit History as a Project Diary
  2. Reading a Commit: Hash, Author, Date
  3. Commit Hash - Your Key to History
  4. How to Find Commits by Author
  5. Filtering Commits by Date
  6. Searching Commit Messages
  7. Combining Filters
  8. The Problem with Reading Commit History
  9. Compact Display with --oneline
  10. Visualizing Branching with --graph
  11. The Full Picture with --all
  12. What is git diff and why do we need it?
  13. Comparing changes in the working directory
  14. What's staged for commit: git diff --staged
  15. Comparing Any Two Commits
  16. How to Examine a Specific Commit in Detail
  17. Practice: Examining Commit Changes
  18. Viewing a Specific File in a Commit
  19. Finding Recent Changes in a File
  20. Analyzing Someone Else's Code Through History
  21. Finding Function Introductions or Removals
  22. Why Commit Messages Matter
  23. Structure of the Perfect Commit Message
  24. Conventional Commits in Practice
  25. Refactoring Bad Commits
  26. Why 'Fix' Commits Are an Anti-Pattern
  27. Atomic Changes: One Commit, One Task
  28. git add -p: The Lifesaver for Clean Commits
  29. Summary and Assignment

บทความเกี่ยวกับบทเรียนนี้

บทเรียนทั้งหมดในคอร์สนี้

  1. Introduction: Git from Scratch to Confident Developer
  2. Why Git is Essential - And Why It's a Job Requirement
  3. Installation and Setup: Getting Git Ready for First Use
  4. First Repository: init, add, commit, and the Magic of the Index
  5. Reading History: log, diff, show and Navigating the Past
  6. Branches: The Parallel Reality of Your Code
  7. Undoing Mistakes: restore, reset, revert — Doing It Right and the Dangers
  8. GitHub and Remote Repositories: Your Code in the Cloud
  9. Team Collaboration: Forks, Feature Branches, and Pull Requests
  10. Merge Conflicts: Don't Panic - Understanding and Resolving Them
  11. Git Workflows in Real Teams: Choosing the Right Approach
  12. Advanced Tools: Rebase, Stash, Cherry-pick and Tags
  13. Final Project: Simulating Real Team Development