How to change last commit message

Change last commit message

So consider I committed changes with the following command (-m to write one line commit message):

git commit -m "fix: big feature X"
git commit --amend -m "fix: small feature X"

Verify new commit message

To check that it worked and I fixed the right commit I check the latest commit with:

git log --oneline
1792519 (HEAD -> master, origin/master, origin/HEAD) fix: small feature X
701aa33 docs: add instructions to README
(END)

Fix pushed commit

In case I already pushed to the remote repository the commit I want to fix, I force the push to remote to update the commit. Preferably, you are working on a feature specific branch, which does not affect the main one (in case this messes the git history for some reason). So this is what I would run, where <branch> is the branch you are working on (e.g.: master).

git push -f origin <branch>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Isabel Costa

Isabel Costa

656 Followers

Software Engineer from Portugal working in the UK • GitHub Star • Open Source advocate • https://isabelcosta.github.io