CS FundamentalsHardAccenture · Capgemini · Git interview
You pushed commit C to a shared branch, then ran git commit --amend to fix its message and tried git push again. What happens and why?
- A. The push succeeds because amend only changes the message, not the commit
- B. The push is rejected as non-fast-forward, because amend created a new commit C' replacing C; forcing it would rewrite history teammates may already have
- C. The push succeeds and Git automatically renames C to C' on the remote
- D. Git refuses the amend itself because C was already pushed
Correct answer: B. The push is rejected as non-fast-forward, because amend created a new commit C' replacing C; forcing it would rewrite history teammates may already have
Any change to a commit's metadata changes its hash, so C' is a sibling of C, not a descendant. The remote sees your branch as diverged; amending published commits is a form of history rewriting.
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 A-B-X, where X was committed after feature branched from B; feature has C-D-E. How many commits are reachable from main after…
- In GitFlow, a critical bug is found in production (main) while develop holds unreleased work. What is the standard handling?
- A team practising trunk-based development wants to merge a half-built feature into main daily without exposing it to users. What makes…
- You have 2 local commits on main and the remote main has 3 new commits. What does git pull --rebase do?
- You staged changes to app.py with git add but now want them out of the next commit while keeping the edits in your working tree. Which…
- During git rebase main, a conflict stops the rebase. You edit the file to resolve it. What should you do next?