nerdexam
Cisco

200-901 · Question #546

A developer is working on a branch called topic that was created from the master branch to add a new feature to the product. After making a few commits on the branch, the developer wants to compare…

The correct answer is C. git diff topic HEAD E. git diff topic master. To compare differences between two Git branches, both specifying both branch names directly and using HEAD as a proxy for the current branch are valid approaches.

Software Development and Design

Question

A developer is working on a branch called topic that was created from the master branch to add a new feature to the product. After making a few commits on the branch, the developer wants to compare the changes between the topic and the master branches. Which two Git commands are used? (Choose two.)

Options

  • Agit diff topic - -cached
  • Bgit diff topic...master
  • Cgit diff topic HEAD
  • Dgit diff topic-master
  • Egit diff topic master

How the community answered

(31 responses)
  • A
    3% (1)
  • B
    6% (2)
  • C
    90% (28)

Why each option

To compare differences between two Git branches, both specifying both branch names directly and using HEAD as a proxy for the current branch are valid approaches.

Agit diff topic - -cached

git diff topic --cached compares the topic branch against the staging area (index), not against the master branch.

Bgit diff topic...master

git diff topic...master uses three-dot notation, which shows only changes introduced on master since the common ancestor with topic - not a direct tip-to-tip branch comparison.

Cgit diff topic HEADCorrect

git diff topic HEAD compares the tip of the topic branch against HEAD, which resolves to the latest commit on the currently checked-out branch. When the user is on master, HEAD equals the master tip, making this functionally identical to a direct branch comparison. It reveals all file-level differences between topic and master without typing the branch name explicitly.

Dgit diff topic-master

git diff topic-master treats 'topic-master' as a single branch or ref name rather than comparing two separate branches, which would result in an error unless that exact ref exists.

Egit diff topic masterCorrect

git diff topic master directly compares the latest commits of the topic and master branches by specifying both names as arguments. This is the most explicit and readable form of the command for comparing two named branches. It produces a complete diff of all changes present in one branch but not the other.

Concept tested: Comparing differences between Git branches using git diff

Source: https://git-scm.com/docs/git-diff

Topics

#Git#Version Control#Branching#Code Comparison

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice