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?

  1. A. The push succeeds because amend only changes the message, not the commit
  2. 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
  3. C. The push succeeds and Git automatically renames C to C' on the remote
  4. 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.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic