Problem
It’s annoying when you commit code changes to a Django project and a bunch of migration, cache files, and other junk get’s unwittingly checked in mucking up the git repo. This is often the case when using the `git add –all’ command.
Assumptions
- The goal is to commit a Django code base without unnecessary migration, caching, etc.
- User would like to use one script to issue a commit command that will first clean things up then commit the code with the message as passed at the command line.
- User is using Git repo.
- sqlite3 in memory DB is used for Django unit test cases and not needed
Solution
Create file clean_commit
and populate with following code.
#!/bin/bash find . -name "*pycache*" -exec rm -r {} \; find . -name "migrations" -exec rm -r {} \; find . -name "db.sqlite3" -exec rm {} \; # Add other cleanup searches here git add --all . git commit -m "$1" git push origin
Usage
./clean_commit "Completed implementation of hello_world module and added unit tests"
Leave a Reply
Your email is safe with us.