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?
- A. git diff shows L1 and L2; git diff --staged shows L1; git diff HEAD shows L2
- B. git diff shows L2 only; git diff --staged shows L1 only; git diff HEAD shows both L1 and L2
- C. git diff shows nothing because the file is staged; git diff --staged and git diff HEAD both show L1 and L2
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- main has commits A-B-C-D. feature was created at B and has commits E-F. How many commits do git log main..feature and git log…
- On main (…-C-D) you run git merge feature, where feature has E-F-G, creating merge commit M. Its first parent is D and its second is G…
- On main with tip D (history A-B-C-D) you accidentally run git reset --hard HEAD~2. Which command brings the branch back to D, assuming…
- A merge commit M on main brought in a feature that turns out to be broken. Running git revert M fails. Why, and what is the fix?
- feature has commits X, then Y, then Z (oldest to newest). On main you run git cherry-pick X..Z. Which commits are applied?
- Your working tree has a modified tracked file f.txt and a new, never-added file u.txt. You run git stash. What does git status show next?