Wether you love our hate git, it is still the most widely deployed version control system. This list has not changed for over a decade, a testament to good software design.

Remove a commit from your history (dangerous)

git rebase -p --onto SHA^ SHA

Remove the last commit

git reset --hard HEAD^

Squash and rebase the last 5 commits into one. Note you can reorder or remove commits by commenting them out.

git rebase -i HEAD~5

Never run git clean without the -i flag, git clean deletes untracked files, it is unlikely you want that to happen, instead use the -i parameter to confirm:

git clean -i

You can also exclude an untracked file or directory by editing the following file:

.git/info/exclude

The rules are the same as .gitignore files except only apply to your local directory. I usually have a directory that I use as a scratch pad for files I don not want to commit. To exclude an already tracked file use the following command:

git update-index --assume-unchanged <file or directory>