Prevent large file commits with PowerShell and Mercurial hooks

Because of Mercurial’s immutable historical record of project files there is no way to make a committed file completely disappear from the history tree. Our only hope in this case it’s not Obi-Wan but the hg rollback command if we act quickly. Since this command only works for one most recent operation (How to keep a Mercurial repository small?) it will not work if we already committed one or more changes after the change that we would like to completely remove (Accidentally committed a large amount of raw data in Mercurial, how do I keep it from overloading my Bitbucket repository?). Our problems escalate even faster if we already pushed or pulled changes to a remote repository and our bad commit propagated to other collaborators.

Two most common cases of brown paper bag commits (a commit that is so bad you want to pull a brown paper bag over your head) are accidentally committing sensitive information files (passwords, connection strings…) and large files. The latter case is less critical because it only increase s repository size and the time it takes to perform operations like pull or clone.

If you are interested in how to prevent yourself from committing large files and are more comfortable with PowerShell then please read on. If you are more of an indentation than squirrely brackets guy then you can check this similar solution in Python - Mercurial hook to disallow committing large binary files.

Read Moreā€¦