#git-amend-safe-or-not
When is `git commit --amend` safe, and when is it not?
Что отвечать
It is safe on a **local commit that has not been pushed yet**. amend creates a new commit with a new SHA (the old one becomes dangling). Physically it is a replace, not an edit. It is dangerous on a pushed commit: after the amend you need a force-push, and if a teammate has already based work on the old SHA, their commits are orphaned. It is also dangerous with `--no-edit` when you do not realize you are changing the author or timestamp: amend rewrites the committer data, the author stays, and that can confuse blame.
Что хотят услышать
A senior should: - explain that amend is a **technically new commit**, not an edit of the existing one. The SHA changes. - name a concrete safe case: "forgot to add a file, typo in the message, not pushed yet" → `git add forgot.txt && git commit --amend --no-edit` - say that after amending a pushed commit you need `git push --force-with-lease`, and if someone already pulled the old SHA, they get a broken history - mention `git commit --amend --reset-author` for the case where you deliberately want to update the author stamp - name `git commit --fixup=<sha>` + `git rebase -i --autosquash` as a more structured amend for a commit that is not the last one
Подводные камни
- ✗ Amending a pushed commit without coordination. Teammates get a broken branch.
- ✗ Thinking `--no-edit` means "nothing changes". The SHA is new anyway.
- ✗ Amending and then running `git push` without force. You get a reject, then you panic-run `git pull` and drag the old commit back in as a merge.
Follow-up
- ? After an amend, does `git log` show both the old and new commit, or only the new one?
- ? How does `git commit --amend --reset-author` differ from a plain amend?
- ? When do you reach for `git commit --fixup=<sha>` instead of amend?
Глубина в базе знаний