exam questions

Exam AZ-400 All Questions

View all questions & answers for the AZ-400 exam

Exam AZ-400 topic 5 question 30 discussion

Actual exam question from Microsoft's AZ-400
Question #: 30
Topic #: 5
[All AZ-400 Questions]

DRAG DROP
-

You use Git for source control.

You delete a file, commit the changes, and continue to work.

You need to recover the deleted file.

Which three commands should you run in sequence? To answer, move the appropriate commands from the list of commands to the answer area and arrange them in the correct order.

Show Suggested Answer Hide Answer
Suggested Answer:

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
kkop
Highly Voted 1 year, 4 months ago
TESTED: git log git checkout [hash]~1 git commit -m 'undeleted file'
upvoted 37 times
vLabz
8 months ago
Approved. 1. git log is necessary to get the hash 2. git checkout hash~1 file-path retrieves the file in STAGED state. The work in progress is not supposed to be staged. And obviously there is no conflict in this scenario because we talk about a single file that is no longer here. So stash is useless. 3. the commit writes the recoverd file to repo, and you can continue your work in progress with your unstaged files git restore is missing the --source parameter if used to retrieve the lost file git restore can be used to unstage the recovered file which is not what we want. git stash is actually useless here
upvoted 3 times
Dankho
4 days, 1 hour ago
and just to add further why stashing not needed - Use Stashing when context-switching or if you need to set aside incomplete work without committing.
upvoted 1 times
...
vLabz
8 months ago
Actually to unstage the file you need to you do git restore --stageg path-to-file we could imagine we wanted just to continue working with unstaged files without commiting anything, but this can't work, because git restore is missing a parameter. This enforces the log / checkout / commit as the solution.
upvoted 1 times
...
...
buzzerboy
1 year, 4 months ago
git log isnt needed. git stash (to keep the current uncommitted changes) git checkout [hash]~1 path/to/file git commit -m "undeleted files"
upvoted 4 times
warchoon
1 year, 4 months ago
You need a log to find the hash
upvoted 21 times
...
...
...
Wengatz
Highly Voted 1 year, 5 months ago
The question says "you continue to work" after you committed the deletion, which means you have in progress changes. In order not to lose those changes, you would need to run a git stash command. To get the hash of the commit that deleted the file, run git log. git checkout [hash]~1 will get 1 commit prior to the commit that deleted the file, which will recover the file. git restore is not needed. So I think the right answer is: git stash git log git checkout [hash]~1
upvoted 18 times
FNog
1 year, 2 months ago
That's true if you checkout the entire commit without specifying a path/file. In the given checkout example, you specify the path to the deleted file, which, since the file no longer exists, will be restored without conflicting with any pending changes hence no need to to stash. 1. git log 2. git checkout [hash]~1 path/to/file 3. git commit -m '"undeleted files'
upvoted 8 times
FNog
1 year, 2 months ago
remark: there's an invalid double dash in the "--path/to/file" which I suspect is just another typo.
upvoted 1 times
...
...
...
4bd3116
Most Recent 1 week, 4 days ago
You use Git for source control. You delete a file, commit the changes, and continue to work. You need to recover the deleted file. Which three commands should you run in sequence?
upvoted 1 times
4bd3116
1 week, 4 days ago
git log -- path/to/file git checkout [previous_commit_hash]~1 -- path/to/file git commit -m 'Restore deleted file'
upvoted 1 times
...
...
hanzocodes
5 months, 3 weeks ago
Log Checkout Commit - Og Checkout that Comet
upvoted 1 times
...
yuu_oppai
8 months, 2 weeks ago
Find the commit hash where the file was last changed: Use git log with the path to the deleted file to find the commit where it was last changed. git log -- [file_path] This will return a list of commits affecting that file. Take note of the commit hash of the commit just before the file was deleted. Restore the deleted file: Use git restore followed by the source option -s or --source and the commit hash, then the path to the deleted file to restore it. git restore -s [commit_hash]^ -- [file_path] The caret (^) symbol refers to the parent commit, effectively restoring the file to its state in the commit just before it was deleted. Commit the restored file: Finally, commit the changes to add the restored file back into your current working branch. git commit -m "Restored [file_path]" if you use the git restore command, you don't need to use git checkout to restore a deleted file. The git restore command is a more modern and direct way to recover deleted files or reset modified ones. It's designed to make this process simpler and more intuitive.
upvoted 1 times
...
gabo
8 months, 3 weeks ago
git restore will restore the file to the last committed version, effectively undoing any changes that have been made since then, but we already got to the file using the git checkout, so the correct order should be git stash (to save current work, optional) git log git checkout git commit
upvoted 1 times
...
xRiot007
11 months ago
This question is such a troll. In a REAL project, the FIRST thing you would do is STASH any work in progress you have. Then, you do a git LOG to see the previous commits. Then, you identify the faulty commit, and do a git CHECKOUT of the prior commit Then, you will do a git COMMIT, to commit the deleted file back to the repo. This question needs serious updating.
upvoted 5 times
...
ShomaV
1 year ago
git log git checkout <commit> -- <file> git add <file> git commit -m "Recover deleted file"
upvoted 4 times
vLabz
8 months ago
git checkout retrieves the file in staged state. the add is useless.
upvoted 1 times
...
Dani_ac7
11 months ago
3, NOT 4 STEPS
upvoted 1 times
...
...
RonZhong
1 year, 2 months ago
git log -- <filename> git checkout <hash>~1 <file name> git commit -m 'undeleted file' https://4ddig.tenorshare.com/windows-recovery-solutions/git-restore-deleted-file.html#f1
upvoted 2 times
yana_b
9 months, 4 weeks ago
This URL is for files, not for branches
upvoted 1 times
...
...
Rams_84zO6n
1 year, 3 months ago
kkop answer is right. The question doesn't say anything about saving your current work (even though it is a good practice). git log -> gives you info on which commit you want to checkout. git checkout will discard your current work and checkout the specific commit. then you commit the change to undelete the file.
upvoted 3 times
...
AlexeyG
1 year, 3 months ago
got this in 02 March 2023 exams. scored 870 marks.
upvoted 5 times
...
Frefren
1 year, 4 months ago
Given answer is correct! Although, I think it's being a bit overcomplicated with the restore. Since I haven't pushed the commit yet, it's only local. So why not: git log git reset --mixed [hash of previous commit] git checkout [filename] This will uncommit the latest commit, bring back the changes to the working tree and then just remove the file deletion, so you can then commit the changes with the same name, ultimately just removing the file deletion.
upvoted 3 times
...
Iaminall
1 year, 5 months ago
Correct
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago