Amend to git commit without changing the commit message
April 16, 2022 ‐ 2 min read
While coding I’m quite often adding changes to a local (work-in-progress) commit. Although it is not that problematic to re-save the current message it can become an annoyance when repeated enough times.
Luckily you can skip the step of editing the commit message when amending changes to a git commit. You can skip editing the commit message by using the
$ git commit --amend --no-edit
You can combine the above command with a
git add . to add all your current changes directly to the last commit you have made in your repository.
$ git add . && git commit --amend --no-edit
Make it an alias
Alright, that allows for skipping the commit message when amending to a git commit but typing that out doesn't save us time :). Maybe a search in previously run commands will do. But you can also choose to either make a git alias or an alias in your terminal shell.
In order to make a git alias you need to make a change to your git config, you can either do that via a command or by opening the git config file. Via the command line it would be like:
$ git config --global alias.amend-no-edit 'commit --amend --no-edit'
The other option would be to add an alias directly to your git config using a text editor. This file can be located in different locations, also depending on your operating system.
Adding a git alias to your git config would look something like the following:
~ % cat ~/.gitconfig [user] name = … email = … [alias] amend-no-edit = commit --amend --no-edit
Obviously you can choose something other than
amend-no-edit. What matters here is that both options allow you to run the command as:
$ git amend-no-edit
Another option would be to add a shell alias instead of a git alias. The above requires you to still use the
git command, using a shell alias you can also get rid of that. In order to add a shell alias you need to add the example below to your shell's config file, which config file depends on the shell you are using (bash, zsh, fish, etc.)
alias amend="git commit --amend --no-edit"
By adding the above to your shell's config file you can run the