These are tried and true steps for cleaning up hastily typed commits or squashing multiple commits to make your git log cleaner.
- Run
git logto see the list of commits. - Run
git rebase -i HEAD~6and 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
ddto 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
pto insert the line back in. - Hit
ito get into INSERT mode. - With the cursor in the same line with the commit you want to squash, delete the word
pickand replace it withsorsquash. Hit ESC to exit the insert mode. - Hit
:wqto 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
:wqto save.
