Rename/Edit/Squash commit(s)

Renaming the latest commit

git commit --amend -m "New commit message"
git push --force origin example-branch

Renaming any commit

For example: renaming HEAD~2 commit (HEAD is latest commit)

git rebase -i HEAD~2  # Replace 2 with the number of commits you want to go back

It will open text editor, You'll see something like this:

find the correct pick <commit hash> message and replace 'pick' to 'reword'

save and exit

git push -f 

(Squash) Replacing x last commits with 1 new single commit

  1. Press F1 and type

    >GitLens: Git Rebase

    then for example, type #<first-commit-hash>

  2. It should open interactive rebase editor like this where you can squash commits:

  1. When you're done, press "START REBASE" and close the git message files that it will open one by one

Last updated