I have a very large Git repository which only contains binary files which are changed pretty often. Naturally the Git repository is much larger than the actual files in it. I don’t really care about old history, I only need some of the newer history to be able to revert some wrong changes. So let’s say I want to remove all commits except the last five.
Naturally I want to do this to keep the repository small so the removed commits must be purged completely from the repo.
And I want to do all this non-interactively with a single command (alias) or script. How can I do this?
Here’s an
rebase-last-fivealias to get you started. It will recreate the current branch so only the most recent five commits are in the history. It’s probably best to make this a script (git-rebase-last-five.sh) that is available in a directory on yourPATH; Git will find and use scripts namedgit-....shwithout the need for any special configuration. The script should do more error checking and handling than this simple alias.CAVEAT EMPTOR: Do heed the warnings about changing history.
Check the
manpages (git help <command>or online) for further information.An example usage: