Sometimes you commit something nasty and need to rewrite it. Or split a commit into parts. Or whatever.
Use case: you want to remove some files from a commit you already made.
Find the commit#
git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=shortSay it’s 4ca80f0.
Remove files from the commit#
git rebase -i 4ca80f0~1Replace pick with edit and save the file.
Unstage everything in that commit:
git reset HEAD^Now all files are back to pre-commit state. Add, remove, or stage as needed.
To undo changes to a tracked file:
git checkout -- windowsFor a new file, just delete it:
rm -rf windowsYou can also split this into several commits.
Change the commit message#
git commit --amendApply the rewrite#
git rebase --continue