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.
1. Read the commit list
Section titled “1. Read the commit list”git loggit 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:
git log --onelineEach line begins with an abbreviated object ID followed by the message subject. The newest reachable commit appears first.
2. Draw and label the graph
Section titled “2. Draw and label the graph”git log --graph --oneline --decorate --all--graphdraws the relationships between commits.--onelineuses a compact representation.--decoratedisplays names such asHEADand branch references.--allincludes 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.
3. Inspect one commit
Section titled “3. Inspect one commit”git show b064868By 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.
4. Filter history
Section titled “4. Filter history”Filter by text in commit messages:
git log --oneline --grep="validation"Use -i when case should not matter. Filter by recorded author identity:
git log --oneline --author="Yousef"Filter by date boundaries:
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.
5. Read the history of a path
Section titled “5. Read the history of a path”Place -- between revision options and a path:
git log --oneline -- App/user.phpThis 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:
git log --oneline --grep="update" -- App/user.phpSearching inside snapshots and finding when particular content was added or removed use other history-investigation tools covered later.
6. Common mistakes
Section titled “6. Common mistakes”- Reading
git logas 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 showto modify or check out the selected commit. - Using
--grepto search file content; it filters commit messages. - Writing a nonexistent
--pathoption instead of the-- <path>separator. - Running a mutating command when a read-only history command answers the question.
7. Summary
Section titled “7. Summary”git log → detailed reachable historygit log --oneline → compact historygit log --graph --oneline --decorate --all → labelled graph from all refsgit show <commit> → metadata and parent-relative patchgit log --grep="text" → filter commit messagesgit log --author="pattern" → filter recorded authorsgit log --since="date" --until="date" → filter datesgit log -- <path> → filter by affected path8. Knowledge check
Section titled “8. Knowledge check”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.