Git Git History and Log 2 — Questions and Answers
Question 1: What does `git blame <file>` show?
- Commits that deleted lines from the file
- Each line of the file annotated with the commit and author that last modified it (Correct answer)
- A list of authors who have ever touched the file
- The original author of the file
Correct answer: Each line of the file annotated with the commit and author that last modified it
The `git blame` command annotates each line of a file with the commit hash, author, and date of the last change to that line.
Question 2: How do you limit `git log` output to commits by a specific author?
- git log --by='Author Name'
- git log --author='Author Name' (Correct answer)
- git log --user='Author Name'
- git log --committer='Author Name'
Correct answer: git log --author='Author Name'
The `--author` flag filters the log to show only commits where the author name or email matches the given pattern.
Question 3: Which command shows commits that exist in `feature` but not in `main`?
- git log main..feature (Correct answer)
- git log feature..main
- git log main...feature
- git diff main feature
Correct answer: git log main..feature
The `main..feature` syntax (double dot) shows commits reachable from `feature` that are not reachable from `main`.
Question 4: What does `git log --since='2 weeks ago'` do?
- Shows commits older than 2 weeks
- Shows only commits made in the last 2 weeks (Correct answer)
- Resets the log to 2 weeks ago
- Shows commits from 2 weeks ago only
Correct answer: Shows only commits made in the last 2 weeks
The `--since` flag (equivalent to `--after`) limits the log to commits made after the specified date or relative time.
Question 5: Which format option for `git log --pretty` displays the full commit hash, author, date, and full message?
- --pretty=short
- --pretty=full (Correct answer)
- --pretty=medium
- --pretty=fuller
Correct answer: --pretty=full
The `--pretty=full` format shows the commit hash, author, committer, and full commit message body.
Question 6: What is the `git reflog` used for?
- Displaying remote logs
- Recording every movement of HEAD and branch tips, including resets and rebases (Correct answer)
- Logging network activity
- Showing only merge commits
Correct answer: Recording every movement of HEAD and branch tips, including resets and rebases
The `git reflog` records a history of all HEAD movements in the local repository, allowing recovery from accidental resets or branch deletions.
What does `git blame ` show?