nerdexam
CompTIA

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.

Troubleshooting

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)
  • A
    8% (5)
  • B
    5% (3)
  • C
    13% (8)
  • D
    75% (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.

Agit branch -b master file

`git branch -b master file` attempts to create a new branch from a file, which is syntactically incorrect and not for reverting files.

Bgit merge master testing

`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.

Cgit stash branch master

`git stash branch master` creates a new branch from a stash entry, which is unrelated to restoring a file from another existing branch.

Dgit checkout master -- fileCorrect

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

#Git#Version Control#File Reversion#Git Commands

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice