CS FundamentalsVery hardProduct-company placement · Git interview

You append line L1 to a tracked file f.txt, run git add f.txt, and then append line L2. Which statement about the three diff commands is correct?

  1. A. git diff shows L1 and L2; git diff --staged shows L1; git diff HEAD shows L2
  2. B. git diff shows L2 only; git diff --staged shows L1 only; git diff HEAD shows both L1 and L2
  3. C. git diff shows nothing because the file is staged; git diff --staged and git diff HEAD both show L1 and L2
  4. D. git diff shows L1 only; git diff --staged shows L2 only; git diff HEAD shows both

Correct answer: B. git diff shows L2 only; git diff --staged shows L1 only; git diff HEAD shows both L1 and L2

git diff compares the working tree with the index (only L2 is unstaged), --staged compares the index with HEAD (L1), and git diff HEAD compares the working tree with HEAD (both). A file can be partly staged.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic