Skip to content

Reading History

Git history is a chain or graph of commits. Reading that history answers two different questions: which commits are reachable, and what did a particular commit introduce? The commands in this lesson are read-only; they do not change the Working Tree, Index, or existing commits.

Terminal window
git log

git log starts from the current revision and follows commit parents backward. By default it shows detailed metadata and messages. For a compact view, put each commit on one line:

Terminal window
git log --oneline

Each line begins with an abbreviated object ID followed by the message subject. The newest reachable commit appears first.

Terminal window
git log --graph --oneline --decorate --all
  • --graph draws the relationships between commits.
  • --oneline uses a compact representation.
  • --decorate displays names such as HEAD and branch references.
  • --all includes history reachable from all local references instead of only the current starting point.

A linear repository appears as one column of stars. A repository with several reachable histories can show multiple lines that split and join. The stars represent commits; the colored lines represent history relationships, not files or directories.

Terminal window
git show b064868

By default, git show displays commit metadata, its message, and the patch it introduced compared with its parent. It does not display a separate full copy of every project file. A root commit has no parent, so its recorded state is shown against an empty starting point.

You can identify a commit with its full object ID or a unique abbreviation. Seven characters are common in compact output, but they are not guaranteed to be sufficient in every repository. If a prefix matches more than one object, Git reports an ambiguous name instead of guessing; provide more characters.

Filter by text in commit messages:

Terminal window
git log --oneline --grep="validation"

Use -i when case should not matter. Filter by recorded author identity:

Terminal window
git log --oneline --author="Yousef"

Filter by date boundaries:

Terminal window
git log --oneline --since="2026-09-20"
git log --oneline --since="2026-09-20" --until="2026-09-21"

These filters inspect commit metadata. --grep searches messages, not file contents.

Place -- between revision options and a path:

Terminal window
git log --oneline -- App/user.php

This shows commits that affected that path. It is not an option named --path; the standalone -- prevents a path from being interpreted as a revision or option.

Filters can be combined. This command requires both a matching message and an effect on the selected path:

Terminal window
git log --oneline --grep="update" -- App/user.php

Searching inside snapshots and finding when particular content was added or removed use other history-investigation tools covered later.

  • Reading git log as oldest-first when its default order begins with recent reachable commits.
  • Treating graph lines as project files.
  • Assuming a short SHA is always unique because seven characters worked once.
  • Expecting git show to modify or check out the selected commit.
  • Using --grep to search file content; it filters commit messages.
  • Writing a nonexistent --path option instead of the -- <path> separator.
  • Running a mutating command when a read-only history command answers the question.
git log → detailed reachable history
git log --oneline → compact history
git log --graph --oneline --decorate --all
→ labelled graph from all refs
git show <commit> → metadata and parent-relative patch
git log --grep="text" → filter commit messages
git log --author="pattern" → filter recorded authors
git log --since="date" --until="date" → filter dates
git log -- <path> → filter by affected path
What happens when an abbreviated SHA matches two objects?

Git reports that the name is ambiguous. Supply enough additional characters to make the prefix unique.

Does git show <commit> change project files?

No. It reads the selected object and normally displays its metadata, message, and patch relative to its parent.

Why does a path come after a standalone –?

The separator distinguishes the path from revisions and command options.