CS FundamentalsVery hardProduct-company placement · Git interview
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. With HEAD at M, which pair is correct?
- A. HEAD^2 is G and HEAD~2 is C
- B. HEAD^2 is C and HEAD~2 is G
- C. HEAD^2 and HEAD~2 are both C
- D. HEAD^2 is F and HEAD~2 is C
Correct answer: A. HEAD^2 is G and HEAD~2 is C
^n picks the n-th parent of a commit, so HEAD^2 = G (the merged-in tip). ~n follows first parents n times: M → D → C, so HEAD~2 = C. They coincide only for non-merge commits' ^1 and ~1.
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
- 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?
- A .gitignore contains the two lines logs/ and !logs/keep.log. A developer expects logs/keep.log to be tracked, but git status never shows…
- A team lead adds a pre-commit hook to .git/hooks/pre-commit in her repository and pushes. Teammates who clone the repository report that…