Q: You need to find out who last changed a specific line in a file, when they changed it, and why. Walk me through how you'd investigate.
Start with git blame:
git blame, git log for a specific line range, and investigation workflow.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "During a major release branch cut, we encountered this exact scenario and used Git internals to recover cleanly. The interviewer is testing: git blame, git log for a specific line range, and investigation workflow.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
Start with git blame:
git blame --ignore-revskips a known bulk-formatting commit. Create a.git-blame-ignore-revsfile listing such commits and configure it globally.git blame -wignores whitespace changes.git blame -Cdetects code moved or copied from other files.
Remediation & Permanent Safeguards
This shows the commit SHA, author, date, and content for line 42. The -L flag limits output to specific lines (-L 40,50 for a range). To understand *why* the change was made: If the blame shows a commit like "Apply formatting" (not the real author), dig deeper: This blames the file at the commit *before* the formatting change. Or use git log -L 42,42:src/auth/login.js to see the full history of changes to that specific line range — every commit that touched those lines, with diffs. For files that have been renamed, add --follow: Pro tips:
git blame -L 42,42 src/auth/login.js
- git blame --ignore-rev skips a known bulk-formatting commit. Create a .git-blame-ignore-revs fil...
- git blame -w ignores whitespace changes.
- git blame -C detects code moved or copied from other files.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring need find last
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring need find last Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring need find last
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring need find last Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.