[git] How to amend a commit without changing commit message (reusing the previous one)?

Is there a way to amend a commit without vi (or your $EDITOR) popping up with the option to modify your commit message, but simply reusing the previous message?

This question is related to git commit git-commit git-amend

The answer is


just to add some clarity, you need to stage changes with git add, then amend last commit:

git add /path/to/modified/files
git commit --amend --no-edit

This is especially useful for if you forgot to add some changes in last commit or when you want to add more changes without creating new commits by reusing the last commit.


git commit -C HEAD --amend will do what you want. The -C option takes the metadata from another commit.


To extend on the accepted answer, you can also do:

git commit --amend --no-edit -a

to add the currently changed files.


Another (silly) possibility is to git commit --amend <<< :wq if you've got vi(m) as $EDITOR.


Using the accepted answer to create an alias

 oops = "!f(){ \
    git add -A; \
    if [ \"$1\" == '' ]; then \
        git commit --amend --no-edit; \
    else \
        git commit --amend \"$@\"; \
    fi;\
}; f"

then you can do

git oops

and it will add everything, and amend using the same message

or

git oops -m "new message"

to amend replacing the message


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to commit

git: updates were rejected because the remote contains work that you do not have locally How to add multiple files to Git at the same time Why Git is not allowing me to commit even after configuration? Git commit in terminal opens VIM, but can't get back to terminal How to configure Git post commit hook GIT commit as different user without email / or only email Editing the git commit message in GitHub How to amend a commit without changing commit message (reusing the previous one)? Temporarily switch working copy to a specific Git commit git - Your branch is ahead of 'origin/master' by 1 commit

Examples related to git-commit

How to undo the last commit in git git status (nothing to commit, working directory clean), however with changes commited Fix GitLab error: "you are not allowed to push code to protected branches on this project"? How to rollback everything to previous commit Troubleshooting misplaced .git directory (nothing to commit) Pushing empty commits to remote Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch How do I commit case-sensitive only filename changes in Git? How to save a git commit message from windows cmd? Remove files from Git commit

Examples related to git-amend

How to amend a commit without changing commit message (reusing the previous one)? Mercurial: how to amend the last commit? How to undo "git commit --amend" done instead of "git commit" How do I push amended commit to the remote Git repository? How to modify existing, unpushed commit messages?