AZ-400 Question 88
Single answerYou�re working on a feature branch for a web application and have already made several commits. In one of these commits, you unintentionally overwrote critical configuration details in 'appsettings.json'. You have the commit hash (abc1234) where the correct configuration last appeared. How can you restore only the old version of 'appsettings.json' from that commit while preserving all other changes made after it?
- A
Use git revert abc1234
- B
Use git checkout abc1234 -- appsettings.json
- C
Use git reset --hard abc1234
- D
Use git cherry-pick abc1234
Show answer and explanation
Correct answer: B
Explanation
When you need to recover specific data for a single file from a previous commit, using the checkout syntax (git checkout
- A. Incorrect.
Incorrect. git revert abc1234 creates a new commit that reverses the changes introduced in that commit. It doesn�t selectively restore a single file; it reverts all changes from that commit, potentially impacting other files you don�t want to revert.
- B. Correct.
Correct. git checkout abc1234 -- appsettings.json pulls the version of 'appsettings.json' from commit abc1234, preserving your current branch state for other files. You can then commit the reintroduced file if desired.
- C. Incorrect.
Incorrect. git reset --hard abc1234 moves your entire branch pointer back to commit abc1234, discarding all changes after that commit. This loses subsequent work rather than selectively restoring just one file.
- D. Incorrect.
Incorrect. git cherry-pick abc1234 applies the entire diff of commit abc1234 to the current HEAD. While it re-applies changes, it doesn�t specifically restore one file from that commit; it reintroduces every change in that commit, which may not be what you want for a single file.