Git: Dealing with .class files and other compiled objects
Lets say I have a couple branches with different code: BranchA and BranchB. Assume I'm currently on BranchA and run a build. Suppose that my build dumps .class files and other compiled objects into directories within the work tree. When I run a diff, I see that directories have changed because they have new compiled objects within.
If I switch to BranchB and deploy my code, then I'm actually deploying objects compiled from BranchA's code base, since git maintained my floating changes (new compiled objects) across the branch switch. This is obviously a mistake.
There are a few ways to avoid this, one being cleaning up non-versioned files whenever we switch branches, but is there a more fool-proof way of taking care of this issue. I'd really rather not put compiled object into version control.
What I do
- use .gitignore to exclude compiled files from the repo
- make a clean and compile part of your deployment process.