🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › Git Version Control for Web & Software Development › Lesson 4
TEC-WEB46-05 · Lesson 4 · 12 clock hours · demo

Viewing and Navigating History

Objective. Students use git log filtering options, git show, and git diff to locate specific commits, compare versions of a file, and interpret the output of each command accurately.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Viewing and Navigating History in Git

One of Git's most powerful features is its complete, permanent record of every change made to a project. Learning to read that record accurately lets you answer questions like: Who changed this file? When did this bug appear? What exactly changed between version A and version B? The commands `git log`, `git show`, and `git diff` are your primary tools for that investigation.

git log — Reading the Commit History

Running `git log` alone prints every commit on the current branch, newest first. Each entry shows the commit hash, author, date, and message. Because real projects can have thousands of commits, Git provides flags to filter and format the output.

Flags can be combined. For example:

```

git log --oneline --graph --all

git log --oneline --author="chen" --since="3 months ago"

```

git show — Inspecting a Single Commit

`git show <commit-hash>` displays the full metadata for one commit (author, date, message) followed by the patch — the exact lines added and removed. You can use the full 40-character hash or the short form shown by `--oneline`. If you omit the hash, Git shows the most recent commit on the current branch.

Reading the patch output uses the same conventions as `git diff` (explained below). `git show` is the right tool when you already know which commit you want to examine in depth.

git diff — Comparing Versions

`git diff` compares two states of the repository and reports what changed. The most common forms you will use are:

Reading Unified Diff Output

Unified diff format is the standard output format for `git diff` and `git show`. Key lines to recognize:

When you write a plain-language summary of a diff, describe what the change accomplishes, not just the mechanics. For example: "The `validateEmail` function was updated to also reject addresses longer than 254 characters" is more useful than "one line was removed and two were added."

Locating a Commit with grep

When you do not know the hash, combine `git log --all --oneline` with the shell pipe and `grep` to search output:

```

git log --all --oneline | grep "login"

```

Alternatively, use Git's built-in `--grep` flag directly, which searches only commit messages:

```

git log --all --oneline --grep="login"

```

Once you have the short hash, pass it to `git show` for the full picture.

Accuracy and Safe Habits

Version control history is a professional record. Never alter published history on shared branches — commands like `git rebase` and `git commit --amend` rewrite commits and can cause serious problems for teammates if used on branches others depend on. In this course you will only read history, not rewrite it.

When working at the command line, verify you are in the correct repository directory before running any Git command (`pwd` on Linux/macOS, `cd` on Windows). Running `git log` in the wrong directory produces confusing results or an error, not data corruption, but developing the habit of confirming your location prevents mistakes when you later use commands that do modify state.

Key terms8

commit hashA unique identifier (SHA-1 checksum) assigned to every commit in a Git repository; can be referenced in full (40 characters) or by a unique short prefix.
HEADA special Git pointer that refers to the currently checked-out commit, typically the latest commit on the active branch; HEAD~2 means two commits before HEAD.
unified diff formatThe standard output format used by git diff and git show; lines prefixed with + were added, lines prefixed with - were removed, and unprefixed lines are unchanged context.
hunkA contiguous block of changed lines within a unified diff, introduced by a header line beginning with @@; each hunk shows the starting line numbers and line counts for the old and new file versions.
--follow flagA git log option that traces a file's history across renames, allowing you to see commits made under the file's previous name.
git showA Git command that displays the metadata and patch (diff) of a single specified commit, or of HEAD if no commit is given.
--grep flagA git log option that filters the commit list to only commits whose commit message contains the specified text string.
context linesUnchanged lines surrounding a changed block in unified diff output; they provide surrounding context to help the reader understand where in the file the change occurred.
In class: Instructor demonstrates git log with flags --oneline, --graph, --all, --author, --since, --grep, and --follow on a prepared sample repository; students follow along on their own terminals and answer a guided worksheet about what each flag does. · Students use git diff HEAD~2 HEAD -- filename to compare a file across two commits, interpret the unified diff output (+ and - lines), and write a short plain-language summary of what changed between those two commits. · Use git show <commit-hash> to inspect a specific commit's metadata and patch, then use git log --all --oneline to locate a commit that introduced a specific keyword using grep piped output; record findings in the lab log.
Materials: Prepared sample Git repository (provided by instructor), terminal, printed unified-diff reference card, lab log
Check: Students correctly answer 8 of 10 questions on a worksheet requiring them to interpret git log and git diff output from printed screenshots; lab log entry signed off.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

CompTIA ITF+ — IT Concepts and Terminology
1. A student runs `git log --oneline` and sees hundreds of commits. Which flag should she add to limit results to commits made by the user whose name contains "torres"?
CompTIA Linux+ — Version Control and Scripting
2. In unified diff output, what does a line beginning with a single `-` character indicate?
CompTIA Linux+ — Version Control and Scripting
3. A developer wants to see a visual ASCII representation of how branches have merged in the repository. Which command produces this output?
CompTIA Linux+ — Version Control and Scripting
4. What does the hunk header `@@ -5,4 +7,6 @@` mean?
CompTIA Linux+ — Version Control and Scripting
5. Which command compares the file `app.js` as it was two commits ago to its current state on the HEAD commit?
CompTIA ITF+ — IT Concepts and Terminology
6. A student wants to find all commits whose commit message includes the word "authentication". Which command is most direct?
CompTIA Linux+ — Version Control and Scripting
7. After a file named `utils.py` was renamed from `helpers.py`, a student runs `git log -- utils.py` but the history before the rename is missing. What should she add to see the full history?
CompTIA ITF+ — IT Concepts and Terminology
8. A student types `git show a3f9c1b`. What will the output include?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.