XK0-005 · Question #1182
XK0-005 Question #1182: Real Exam Question with Answer & Explanation
The correct answer is D: git checkout master -- file. To revert a specific file in a testing branch to its version from the master branch, the git checkout master -- <file> command is the best option.
Question
An issue was discovered on a testing branch of a Git repository. A file was inadvertently modified and needs to be reverted to the master branch version. Which of the following is the BEST option to resolve the issue?
Options
- Agit branch -b master file
- Bgit merge master testing
- Cgit stash branch master
- Dgit checkout master -- file
Explanation
To revert a specific file in a testing branch to its version from the master branch, the git checkout master -- <file> command is the best option.
Common mistakes.
- A.
git branch -b master fileattempts to create a new branch namedmasterfrom a file, which is not a valid Git operation for reverting a file. - B.
git merge master testingwould attempt to merge changes from thetestingbranch into themasterbranch (or mergemasterintotestingif run fromtesting), which is about combining changes, not selectively reverting a single file. - C.
git stash branch mastercreates a new branch and then applies a stashed state to it, which is unrelated to reverting a specific file from another existing branch.
Concept tested. Git checkout specific file from branch
Reference. https://git-scm.com/docs/git-checkout
Topics
Community Discussion
No community discussion yet for this question.