AZ-400 · Question #427
Drag and Drop Question 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 sequenc
The correct answer is git log; git checkout [hash]~1 --path/to/file; git commit -m 'undeleted the file'. To recover a deleted file in Git after committing the deletion, you first run 'git log' to find the commit hash where the file still existed. Then 'git checkout [hash]~1 --path/to/file' checks out the file from the commit just before the deletion (the tilde-1 notation means 'one
Question
Exhibit
Answer Area
Drag items
Correct arrangement
- git log
- git checkout [hash]~1 --path/to/file
- git commit -m 'undeleted the file'
Explanation
To recover a deleted file in Git after committing the deletion, you first run 'git log' to find the commit hash where the file still existed. Then 'git checkout [hash]~1 --path/to/file' checks out the file from the commit just before the deletion (the tilde-1 notation means 'one commit before the specified hash'). Finally, 'git commit -m' stages and commits the recovered file back into the repository's history.
Topics
Community Discussion
No community discussion yet for this question.
