Git: How to prevent committing files that were modified just for debugging purposes?

git, perforce

Solution

Thanks all for the answers. What I ended up doing is writing a pre-commit hook in git that checks for the string "dont commit" (and other variations) in each of the files. If it does, then the commit fails, and I'll have to edit those lines before committing. This is because debug code should be treated on a per-line basis, not per-file, because some files have both debug changes and real changes to be committed. (my old solution with perforce did not address this issue).

Problem

A lot of times, I like to modify some lines of code in order to make debugging easier, but I don't actually want to commit them. For instance, I'll disable some annoying features (like ads) by commenting out some lines of code, or I'll set the log levels and filters to only the ones I care about, or I'll force a conditional to be true just so the block of code I want to run actually runs all the time. In Perforce, I would have created a "changelist" for these files and labeled it as "DON'T COMMIT!". What would be the equivalent of this in Git? A branch doesn't work because these debug-only modifications need to exist with other changes I'm currently making.

Original source

Related problems