What is the difference between git commit --amend and a standard commit?
Last updated
A standard commit creates a brand-new commit on top of the current tip; git commit --amend replaces the most recent commit with a new one, letting you fix its message or contents without adding a separate commit.
Standard commit: Adds a new commit whose parent is the current
HEAD; history grows by one.Amend rewrites HEAD:
Combines the staged changes with the previous commit's content and produces a new commit object with a new SHA (the old one is discarded).
Common uses: fix a typo in the message, or add a forgotten file to the last commit.
It rewrites history: Since the SHA changes, never amend a commit already pushed and shared, or you force others to reconcile a diverged history (needs
--force-with-lease).Message-only amend: Run
git commit --amendwith nothing staged to edit just the message.
- https://www.reddit.com/r/cscareerquestions/comments/bxxwfc/what_are_some_behavioral_questions_you_have_been/
- https://www.reddit.com/r/rails/comments/1shfrbq/3_years_rails_dev_but_failed_basic_interview/
- https://www.reddit.com/r/cscareerquestions/comments/u7z2xh/how_often_do_developers_look_at_git_trees/