In my opinion, Git is a programmers program. It is fast, feature-rich yet intuitive, kind of like Google...there's a new treasure waiting to be found around every corner. The philosophy behind Git appeals to me; there's sure to be a lot to learn by appreciating it's architecture and studying its internals.

One of the few things that bugs me about Git is what happens when you finally realize that you have been committing unnecessary -massive- binaries such as database files and executables -especially if they are modified frequently.

The problem here is that if any single bit changes, the repository must make a new, albeit compressed copy of the whole mess, while of course keeping all previous copies archived for future reference... This situation sees the repository size quickly bloat.  While there are (Git)  methods to undo such mistakes, it's by no means easy or fun to do. At least for myself, I am not proficient enough with Git to fully understand the entire process.

I've been doing a fair bit of compiling lately and have found the output binaries are getting in the way of my workflow -sure there are means to avoid this such as having make files output to /bin directories and then explicitly reference them in a .gitignore file, but that's not practical in my situation.

In Windows environments things are actually a little easier as file extensions are almost always employed and they make filtering a snap. In Linux, however, things are a little trickier...

As such, I've put together a script that employs the file  utility in order to identify file MIME types, filter and then automatically add to them to .gitignore. It can run from within any directory of the repo in order to create per-directory .gitignore files, however executing it from the repo's root to create a top level .gitignore is probably good enough, and more maintainable.

If there's a need, I might implement a recursive maintenance utility, but for now it only deals with a single gitignore within the current working directory.

AutoGit -automatically filter files by their MIME type to avoid binary files, databases and other undesired content types.

Here's a direct link to the AutoGit bash script on GitHub.

$ Save it as a text file named autogit or something else flavorful.
$ chmod +x autogit
$ put it in the root of your git repo OR even better, place it in your PATH somewhere like /usr/share/bin
$ cd /your/git/repo
$ do autogit or ./autogit as appropriate
$ autogit will append the filepaths it found that have been identified and dump a report + git status
$ By default, the MIME types application/x-executable and application/octet-stream are enabled. Edit the script to add/modify desired MIME types.

Picture is of marshland adjacent to Pitt Lake near my place... I originally emailed this post in from my iPhone 4 which looked OK in the mobile version of Blogger, but had weird line breaking going on that I had to later undo from a browser...Just me testing.

0 comments:

Dynamic Page QR Code

Popular Posts

My LinkedIn PingTag


View My Stats