Git & GitHub
/Beginner
git log
Definition
Shows the commit history for the currently active branch.
Explain Like I'm New
Reading the diary of your project. It prints out a scrolling list of every save point ever made, starting from the most recent.
Real World Example
Trying to figure out who broke the website. You run `git log`, read the recent messages, see a commit titled 'Delete important database config', and find the email address of the person who did it.
Common Use Cases
- •Reviewing project history
- •Finding specific commit hashes to revert to
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| --oneline | Compress each commit to a single line (hash + message). |
| --graph | Draw a text-based graphical representation of the commit history. |
| -p | Patch. Show the actual code differences introduced in each commit. |
| -n [num] | Limit the number of commits to show. |
Terminal Output
bash / terminal
# View standard detailed history
$ git log
# View a condensed, single-line version of the history (Super useful!)
$ git log --oneline
# Output: a1b2c3d Fix login bug
# Output: e4f5g6h Add user profile page
# View the beautiful ASCII tree graph of branches
$ git log --graph --oneline --all
# View only the last 3 commits
$ git log -n 3
Interview Questions
basic
- How do you exit the `git log` screen when it takes over your terminal?
intermediate
- How can you make `git log` output look like a visual graph instead of a wall of text?