Git Git History and Log 1 β Questions and Answers
Question 1: Which command shows a compact one-line summary of each commit in the log?
- git log --short
- git log --oneline (Correct answer)
- git log --summary
- git log --brief
Correct answer: git log --oneline
The `git log --oneline` flag formats each commit as a single line showing the abbreviated hash and subject message.
Question 2: What does `git log -p` display?
- Only commit authors
- Each commit along with the diff it introduced (Correct answer)
- A graph of branch history
- Commits sorted by patch size
Correct answer: Each commit along with the diff it introduced
The `-p` (or `--patch`) flag shows each commit entry together with the full diff of changes introduced by that commit.
Question 3: Which command searches the commit log for commits whose message contains a specific string?
- git log --find='string'
- git log --grep='string' (Correct answer)
- git log --search='string'
- git log --match='string'
Correct answer: git log --grep='string'
The `--grep` flag filters the commit log to show only commits whose message matches the given pattern.
Question 4: How do you view the commit history for a specific file?
- git log <file>
- git log -- <file> (Correct answer)
- git history <file>
- git log --file=<file>
Correct answer: git log -- <file>
Using `git log -- <file>` shows only the commits that modified the specified file, with the `--` disambiguating the file path from a branch name.
Question 5: What does the `git shortlog` command produce?
- A log with abbreviated hashes
- A summary of commits grouped by author (Correct answer)
- The last 5 commits only
- A log without merge commits
Correct answer: A summary of commits grouped by author
The `git shortlog` command groups commits by author and shows the count and subject lines for each author's commits.
Question 6: Which option shows a visual ASCII graph of branch and merge history in `git log`?
- --tree
- --graph (Correct answer)
- --visual
- --branches
Correct answer: --graph
The `--graph` option draws an ASCII representation of the commit graph alongside the log output.
Which command shows a compact one-line summary of each commit in the log?