CS FundamentalsVery hardProduct-company placement · Git interview
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?
- A. Merge commits can never be reverted; reset main instead
- B. A merge has two parents, so git must be told which side is the mainline: git revert -m 1 M
- C. git revert works only on the latest commit; use git revert HEAD~1
- D. The working tree must first be cleaned with git clean -fd
Correct answer: B. A merge has two parents, so git must be told which side is the mainline: git revert -m 1 M
git refuses ('is a merge but no -m option was given') because it cannot know which parent to diff against. -m 1 keeps main's side and undoes the feature's changes. Note that re-merging the feature later needs care, because its commits are already in history.
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
- 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…
- After rebasing your branch you must update the remote branch. A colleague may have pushed to the same branch meanwhile. Why prefer git…
- You create an annotated tag v2.0 locally and run git push. The tag does not appear on the remote. What is correct?