git status – What's Happening Right Now
git status is the first command to run whenever you're unsure about the state of your working directory. It never modifies anything — it only reports. Run it freely and often.
git status
Reading the Status Output
The output is divided into three sections. Here is a real example with all three present at once:
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: src/utils.py
new file: src/helpers.py
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
experiments/scratch.py
| Section | Meaning | Next action |
|---|---|---|
| Changes to be committed | Files in the staging area — ready for the next commit | git commit to save, or git restore --staged to unstage |
| Changes not staged | Modified tracked files that are NOT yet staged | git add to stage, or git restore to discard |
| Untracked files | New files Git has never seen — Git ignores these until you add them | git add to start tracking, or add to .gitignore |
Run git status -s (or --short) for a compact two-column view. Left column = staging area, right column = working tree. M = modified, A = added, ? = untracked. Example: M src/utils.py means modified and staged; M README.md means modified but not staged.
git log – Exploring Commit History
git log displays the repository's commit history, most recent first. Each entry shows the commit hash, author, date, and message.
git log
commit a3f8c2d1b4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9 (HEAD -> main, origin/main)
Author: Alex Kim <alex@example.com>
Date: Mon Jun 8 14:23:11 2026 +0600
Add input validation to calculate function
commit 7b9e1a3c2d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8
Author: Alex Kim <alex@example.com>
Date: Sun Jun 7 10:05:44 2026 +0600
Initial project setup
Press q to exit the log pager when there are many commits.
Useful Log Formats
One-line format — most readable for quick review
git log --oneline
a3f8c2d (HEAD -> main, origin/main) Add input validation to calculate function
7b9e1a3 Initial project setup
Visual branch graph — the most useful command for multi-branch work
git log --oneline --graph --all
* a3f8c2d (HEAD -> main) Add input validation
| * f1e2d3c (feature/login) Add login form
| * 9a8b7c6 Start login feature
|/
* 7b9e1a3 Initial project setup
The ASCII art graph shows where branches diverged and merged. The * marks commits; |, /, and \ draw the branch lines. This is invaluable when working with multiple branches.
Most developers create a short alias for the graph log: git config --global alias.lg "log --oneline --graph --all". Then just type git lg.
Filtering the Log
On large projects with thousands of commits, you'll need to filter the log output.
# Show only the last 5 commits
git log -n 5
git log -5 # shorthand
# Filter by author (partial match works)
git log --author="Alex"
# Filter by date range
git log --since="2 weeks ago"
git log --since="2026-01-01" --until="2026-06-01"
# Search commit messages with a keyword
git log --grep="login"
# Show commits that changed a specific file
git log -- src/utils.py
# Combine filters
git log --oneline --author="Alex" --since="1 month ago"
git show – Inspect a Specific Commit
git show displays the full details of a single commit: the metadata (author, date, message) plus the diff of every file it changed.
# Show the most recent commit (HEAD)
git show
# Show a specific commit by its hash (first 7 chars is enough)
git show a3f8c2d
# Show a commit and only list the changed file names (no diff content)
git show a3f8c2d --stat
# Show the content of a specific file at a specific commit
git show a3f8c2d:src/utils.py
commit a3f8c2d1b4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9
Author: Alex Kim <alex@example.com>
Date: Mon Jun 8 14:23:11 2026 +0600
Add input validation to calculate function
src/utils.py | 3 +++
1 file changed, 3 insertions(+)
📋 Summary
- git status — the go-to command to see what's staged, unstaged, and untracked; run it before every commit.
- Status output has three sections: Changes to be committed (staged), Changes not staged (modified but not staged), and Untracked files (new files).
- git log — shows full commit history; most recent first.
- git log --oneline — compact one-line per commit;
--graph --alladds a visual branch diagram. - Filter logs with
--author,-n,--since,--grep, or by filename. - git show <hash> — show a specific commit's full diff;
--statfor a file-level summary.
FAQ
This usually means your file is listed in .gitignore, so Git is intentionally ignoring it. Check with git status --ignored to see ignored files. Another possibility: the file might not actually be saved yet (the editor hasn't written it to disk). Rarely, on certain operating systems, line-ending conversion settings (core.autocrlf) can make a file appear unchanged even after editing — though this is uncommon.
Use git blame <filename>. It annotates every line with the commit hash, author name, and date of the last change to that line. Example: git blame src/utils.py. Many Git GUI tools and VS Code's GitLens extension show blame information inline as you read code.
HEAD is a pointer to your current position in the repository — usually the tip of your current branch. When you see (HEAD -> main) in git log, it means you are on the main branch and its latest commit is the one marked HEAD. When HEAD points directly to a commit hash instead of a branch, you are in "detached HEAD" state — which is normal when checking out a specific commit, but you should create a branch before making new commits in that state.
Yes — use git log --all -- path/to/deleted-file.py. The -- separator tells Git to interpret what follows as a file path, not a branch name. This shows all commits that touched the file, even after deletion. To recover the file's last content, run git show <last-commit-hash>:path/to/deleted-file.py or restore it with git checkout <commit> -- path/to/deleted-file.py.