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.
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)- A3% (1)
- B6% (2)
- C90% (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.
git diff topic --cached compares the topic branch against the staging area (index), not against the master branch.
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.
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.
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.
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
Community Discussion
No community discussion yet for this question.