AZ-400 exam dumps

AZ-400 practice question 89 of 306

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

AZ-400 Question 89

Single answer

You are a DevOps engineer working on a feature branch for a new payment gateway. You realize you�ve accidentally removed important environment variables in your most recent commit to the 'config.yaml' file, but you want to keep the rest of your changes. You need to recover only the missing variables from the previous commit (HEAD~1) while preserving other modifications in 'config.yaml'. Which command should you use to restore just those specific lines from the previous commit?

  1. A

    git revert HEAD~1

  2. B

    git restore --source=HEAD~1 -- config.yaml

  3. C

    git restore --staged HEAD~1 config.yaml

  4. D

    git restore --source=HEAD~1 -p config.yaml

Show answer and explanation

Correct answer: D

Explanation

When you need to recover specific lines or chunks from a previous commit in Git, using the 'git restore' command with '-p' (partial or patch mode) is the most flexible approach. It lets you select exactly which parts of the file to restore, preserving any new changes you do not wish to discard. For more details, refer to the Git documentation at https://git-scm.com/docs/git-restore.

  • A. Incorrect.

    Option 1: 'git revert HEAD~1' creates a new commit that reverses all changes from the specified commit. It does not allow you to selectively restore certain lines from the file; it undoes the entire commit. This is incorrect for recovering only specific data.

  • B. Incorrect.

    Option 2: 'git restore --source=HEAD1 -- config.yaml' replaces the entire 'config.yaml' with the version from the previous commit. While it brings back the removed variables, it also discards all other changes introduced after HEAD1 in that file. This is not the best choice for selectively restoring specific lines.

  • C. Incorrect.

    Option 3: 'git restore --staged HEAD~1 config.yaml' attempts to affect the staging area from a previous commit. This does not target retrieving lines from the working tree in a partial manner and does not solve selectively restoring missing lines in the file.

  • D. Correct.

    Option 4: 'git restore --source=HEAD~1 -p config.yaml' uses the partial patch mode (-p) to let you interactively select which lines to restore from the previous commit. This allows you to recover only the missing environment variables without overwriting other changes.

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