These are tried and true steps for cleaning up hastily typed commits or squashing multiple commits to make your git log cleaner.
- Run
git log
to see the list of commits. - Run
git rebase -i HEAD~6
and set the number to the number of commits you want to see. 6 for eg, will allow you to edit your 6 most recent commits. - Refer to the Vim commands cheat sheet: http://vim.rtorr.com/ for possible operations.
- Move your cursor to the commit you want to move and type
dd
to cut the line. - If you want to merge two commits into one, move your cursor to the commit you want to squash it with and press
p
to insert the line back in. - Hit
i
to get into INSERT mode. - With the cursor in the same line with the commit you want to squash, delete the word
pick
and replace it withs
orsquash
. Hit ESC to exit the insert mode. - Hit
:wq
to write changes and quit. - It will attempt the rebase then prompt you to select the commit message you want, or write a new one.
- Hit i to insert some text and use # to comment out lines.
- When you're done, hit
:wq
to save.