Fixing commits
This is mostly from here.
Fixing the last commit
Changing the last commit message
git commit --amend -m "New message"
Changing the last commit
Make your changes to the files
Run
git add <filename>to add one file orgit add <filename1> <filename2> ...to add multiple filesgit commit --amend
Fixing older commits
Changing commit messages
git rebase -i HEAD~5(if, for example, you are editing some of the last five commits)For each commit that you want to change the message, change
picktoreword, and saveChange the commit messages
Deleting old commits
git rebase -i HEAD~nwherenis the number of commits you are looking atFor each commit that you want to delete, change
picktodrop, and save
Squashing commits
Sometimes, you want to make one commit out of a bunch of commits. To do this,
git rebase -i HEAD~nwherenis the number of commits you are interested inChange
picktosquashon the lines containing the commits you want to squash and save
Reordering commits
git rebase -i HEAD~nwherenis the number of commits you are interested inReorder the lines containing the commits and save
Pushing commits after tidying them
git push origin +my-feature-branch(Note the+there and substitute your actual branch name.)