FresherTechnicalGit
What do git log --oneline --graph and other log options show?
Try answering first
Model answer
git log lists commits from newest to oldest, starting at HEAD. By default each entry is long, so options reshape it.
--onelineprints one line per commit: short hash and subject.--graphdraws the branch and merge structure with ASCII lines.--decoratelabels commits with branch and tag names, and--allincludes every branch, not just the current one.-n 10limits the count.- Filters:
--author="Ana",--since="2 weeks ago",--grep="login", and-- path/to/filefor one file.
git log --oneline --graph --decorate --all
git log --since="1 week ago" --author="Ana" --oneline
git log -p -- src/auth.ts
Example output:
* 3f2a1bc (HEAD -> main, origin/main) Merge pull request #42
|\
| * 9d8e7c6 (feature/login) Add login validation
|/
* 1a2b3c4 Initial commit
Reading it tells you where branches diverged and merged. Many people save the first command as an alias, such as git lg.
Key points
- log lists commits from HEAD backwards
- --oneline and --graph give a compact picture of branches
- --all includes every branch
- Filter by author, date, message or path
Likely follow-ups
- How do you create an alias for this command?
- How do you see only merge commits?
Common mistakes
- Forgetting --all and thinking other branches are missing
- Scrolling a huge unfiltered log instead of using filters