Change commit messages, drop or squash commits in git

If you want to change commit messages or remove commit messages you'd done in a branch, or even squash commits together into one to keep the history clean, you can do the following:

First, make sure your editor you use for git is set correctly. I prefer nano, but others use vim:

$ git config --global core.editor nano 

Second, rebase your current branch interactively (-i) onto another branch. Mostly you want to rebase on develop, so I use develop in this example:

$ git rebase -i develop 

Now you are able to squash and edit commits, even drop whole commits by editing the words "pick" in front of each commit to one of these:

# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

Save and exit your editor, and follow the instruction in the terminal. For nano it would be CMD + x and choosing Y for yes. Git will now rebase according to your script.