How to prevent git from committing if there are unverified files?

Sometimes it makes sense to prevent git from committing when there are raw files, because you have to add them either to the files for fixing or to gitignore. And an option like -f to force a commit is also necessary. So, is there a / plugin / etc option for this? Thank you very much.

+4
source share
1 answer

You can add a pre-commit that exits with a non-zero value if you find unnecessary files (you could examine the output of git status --porcelain -u to determine their presence - find lines starting with "?"). You can then override the commit check with git commit --no-verify if you are not interested in unused files.

Edit: thanks @Jefromi; I don't have my git environment for testing. He also notes that this command should identify the presence of unprocessed files: git status -u | grep '^# Untracked files:$' git status -u | grep '^# Untracked files:$' .

+5
source

All Articles