XK0-005 · Question #187
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…
The correct answer is D. git checkout master -- file. When a file on a testing branch has been inadvertently modified and needs to be reverted to its version from the master branch, a specific Git command can be used.
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
How the community answered
(64 responses)- A8% (5)
- B5% (3)
- C13% (8)
- D75% (48)
Why each option
When a file on a testing branch has been inadvertently modified and needs to be reverted to its version from the master branch, a specific Git command can be used.
`git branch -b master file` attempts to create a new branch from a file, which is syntactically incorrect and not for reverting files.
`git merge master testing` would attempt to integrate changes between the two branches, not revert a single file to a previous state from another branch.
`git stash branch master` creates a new branch from a stash entry, which is unrelated to restoring a file from another existing branch.
The `git checkout <branch> -- <file>` command allows you to discard local changes for a specific file or replace it with the version from a specified commit or branch. Using `git checkout master -- file` will replace the `file` in the current `testing` branch with the version it has in the `master` branch.
Concept tested: Git reverting specific files from another branch
Source: https://git-scm.com/docs/git-checkout
Topics
Community Discussion
No community discussion yet for this question.