AZ-400 exam dumps

AZ-400 practice question 90 of 306

Designing and Implementing Microsoft DevOps Solutions. Professional level, Microsoft. Free question with the correct answer and a full explanation.

AZ-400 Question 90

Single answer

You are working on a microservices-based project using Git for source control. A developer has inadvertently overwritten a crucial config file (config.yaml) with invalid data and pushed the changes to the main branch. You need to recover only that file from the last known good commit (commit hash: 1a2b3c) and keep all other changes intact in your working tree. Which command should you use?

  1. A
    1. git checkout 1a2b3c -- config.yaml
  2. B
    1. git revert 1a2b3c
  3. C
    1. git reset --hard 1a2b3c
  4. D
    1. git revert HEAD~1 -- config.yaml
Show answer and explanation

Correct answer: A

Explanation

To recover a specific file from a previous commit, you can use 'git checkout <commit_hash> -- <file_name>' (or the newer 'git restore --source=<commit_hash> <file_name>'). These commands allow you to restore just that file from the given commit, preserving all other changes. For more information, refer to the official Git documentation on 'git checkout' or 'git restore.'

  • A. Correct.

    Option 1: git checkout 1a2b3c -- config.yaml. Correct. This command checks out only the specified file from the given commit, leaving other files and commits untouched. It's the typical method to recover a specific file from a particular commit without affecting other changes in the working directory.

  • B. Incorrect.

    Option 2: git revert 1a2b3c. Incorrect. This command creates a new commit that undoes all changes introduced by commit 1a2b3c, not just a single file. It replaces the entire commit rather than restoring one file, which is more disruptive than what you need here.

  • C. Incorrect.

    Option 3: git reset --hard 1a2b3c. Incorrect. This command resets the entire repository to commit 1a2b3c, discarding all changes made after that commit. This would lose additional work instead of just restoring one file.

  • D. Incorrect.

    Option 4: git revert HEAD~1 -- config.yaml. Incorrect. 'git revert' does not directly allow reverting changes on a single file; it reverts entire commits. Specifying a file path with revert does not achieve the desired outcome of only restoring that file from a specific commit.

Timed practice exam

Take a AZ-400 practice test under exam conditions

70 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam