git commit amend without changing message code example

Example 1: change git commit message

git commit --amend -m "New commit message"

Example 2: git amend commit message after push

$ git commit --amend -m "New and correct message"

Example 3: git commit amend without changing message

git commit --amend --no-edit

Example 4: git reset amend

# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before 
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
git reset --soft HEAD@{1}

# commit the current tree using the commit details of the previous
# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the
# previous command. It's now pointing at the erroneously amended commit.)
git commit -C HEAD@{1}

Example 5: add change to last commit

$ (some_branch) git commit --amend