To retrieve an earlier version of a file without losing current uncommitted work, stash the current changes first, check out the old version of just that file, then reapply the stash on top of it.
A developer wants to see how OrderService.java looked three commits ago while keeping their current unfinished edits; they stash, run git checkout HEAD~3 -- OrderService.java, review the old logic, and then pop the stash back on.
git stash
git checkout HEAD~3 -- OrderService.java
git stash popA concise interview answer is
I'd stash my current changes to get a clean working directory, then check out the earlier version of just that file using git checkout with the commit hash and file path. Once I've retrieved what I need, git stash pop brings my in-progress changes back on top.
Last updated: 11 November 2026
Previous question: Explain how Git hooks can enhance your workflow in a team setting.
Next question: How can you track changes made by others in a shared repository?