Commit history shows the path a change took: when a setting changed, which branch introduced it and where it was merged. Learn to read that graph and HEAD before using diff and bisect to narrow a problem. The history becomes diagnostic evidence rather than a list of changes to delete.
Use a repository with two or more commits, like gitops-demo created in Part 5. The query commands in this article do not change your working files. Before starting a checkout or bisect, unfinished work is committed or set aside.
Git · GitOps All Series · 06 / 24
On this page
View the entire graph and individual changes separately
git status --short --branch
git log --oneline --graph --decorate --all -15
git show --stat HEAD
git show HEAD -- README.md
git diff HEAD~1 HEAD -- README.md
--graph draws the parent relationship, and --decorate displays the location pointed to by the branch or tag. Hashes are not chronological numbers, so font size or number does not determine which commit was made first. HEAD~1 is the first parent of the current commit and does not exist in the first commit.
When following changes to a specific file, you specify a path. What follows -- means a path, so ambiguity can be reduced even if the branch name and file name overlap.
git log --oneline -- README.md
git log -p -2 -- README.md
git blame README.md
blame shows which commit the current line comes from. It is not a tool to blame the person responsible or determine the cause of the bug. You may see commits that have moved lines or changed formatting, so read their descriptions and forward/backward changes as well.
Why commits are graphs
Git uses a blob, which is the file content, a tree, which contains the file name and configuration, and a commit object, which points to the tree and its parents. Commits refer to previous commits, so the history forms a directed acyclic graph, or DAG. A merge commit can have more than one parent.
git rev-parse HEAD
git cat-file -t HEAD
git cat-file -p HEAD
tree, parent, creation information and messages appear on directly viewed objects. Object IDs are content-based, so even if the commit message or parent changes, it will have a new ID. Because of this, when you stack changes back with a rebase, the commit hashes will be different even if the file contents are similar.
A branch is a name that points to a specific commit, not the folder where this object is copied as a whole. HEAD usually points to the current branch, and making a new commit moves that branch forward.
detached HEAD to view past states
git status --porcelain
git switch --detach HEAD~1
# Inspect files here. Do not start unrecorded work.
git switch main
If you check out a commit directly instead of a branch, it is in detached HEAD state. You can still create commits in this state, but if you move them without creating a name to return to, they may become difficult to find. To preserve your work here, create a branch like git switch -c inspect-fix before moving.
Narrow down the commits where the problem started by half.
If you have hundreds of commits, git bisect is useful. By splitting the check between healthy and problem commits, you can narrow down the candidates with fewer decisions than reading them linearly one by one. However, the same test must succeed or fail with the same criteria.
# Replace GOOD_COMMIT with a known-good commit ID.
git bisect start
git bisect bad HEAD
git bisect good GOOD_COMMIT
# Test the selected commit, then mark one result:
git bisect good
# Repeat with good or bad until Git identifies a commit.
git bisect reset
The above good only displays when the actual test passes. Automation can use git bisect run 테스트명령, but it must distinguish between a test not being executable and a failure. If your history is still short, it is enough to learn the log → show → diff sequence for now.
The object structure was explained based on Git Internals: Git Objects, and the search method was explained based on git bisect.
Previous · [Git and GitOps 05] Make a First Commit with add, commit, status and diff · Next · [Git and GitOps 07] Choose restore, reset or revert Before Undoing Changes · Series list and example files



