Junior corrupted a PR by running git commit --amend on a shallow clone checkout, causing the amended commit to include every file in the repo as new additions (139 files changed).
Sequence
- Shallow-cloned
getsentry/skills to branch main
- Created branch, made targeted edits (2 files), committed
- Pushed branch, opened PR — diff was correct (+6/-2)
- Needed to revise the commit — ran
rm -rf on the clone dir
- Re-cloned with
--depth=1 -b jr/fix-placeholder-issue-refs (shallow clone of the feature branch)
- Made edits, ran
git commit --amend --no-edit
- The shallow clone had no shared history with
main, so the amend treated every tracked file as new in the commit
- Force-pushed — PR diff ballooned to 22k+ insertions across 139 files, PR was closed
Root cause
git commit --amend on a depth-1 clone of a feature branch produces a commit whose tree diff against main includes every file, because the shallow clone lacks the merge-base. The correct approach is either:
- Re-clone from
main (not the feature branch), recreate the branch, and make a new commit
- Or avoid amending entirely — just add a fixup commit
Proposed guardrail
Before running git commit --amend or git rebase, verify the clone has sufficient history to compute a clean diff against the PR base branch. If depth=1, either deepen (git fetch --deepen) or use a new commit instead of amending.
Observed in getsentry/skills#147 (closed).
Action taken on behalf of David Cramer.
Junior corrupted a PR by running
git commit --amendon a shallow clone checkout, causing the amended commit to include every file in the repo as new additions (139 files changed).Sequence
getsentry/skillsto branchmainrm -rfon the clone dir--depth=1 -b jr/fix-placeholder-issue-refs(shallow clone of the feature branch)git commit --amend --no-editmain, so the amend treated every tracked file as new in the commitRoot cause
git commit --amendon a depth-1 clone of a feature branch produces a commit whose tree diff againstmainincludes every file, because the shallow clone lacks the merge-base. The correct approach is either:main(not the feature branch), recreate the branch, and make a new commitProposed guardrail
Before running
git commit --amendorgit rebase, verify the clone has sufficient history to compute a clean diff against the PR base branch. If depth=1, either deepen (git fetch --deepen) or use a new commit instead of amending.Observed in getsentry/skills#147 (closed).
Action taken on behalf of David Cramer.