How to forbid git commit if there are untracked files?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 13:08:56

问题


Sometimes, it makes sense to forbid git commit when there are untracked files, because you should add them either to files to commit or gitignore. And an option like -f to force this commit is also necessary. So is there any option/plugin/etc to do that? Thank you very much.


回答1:


You can add a pre-commit hook that exits with a non-zero value if you find untracked files (you could examine the output of git status --porcelain -u to determine their presence--look for lines beginning with "?"). Then you can override the commit verification with git commit --no-verify if you don't care about the untracked files.

Edit: Thanks to @Jefromi; I don't have my git environment at hand to test. He also notes that this command should identify the presence of untraced files: git status -u | grep '^# Untracked files:$'.



来源:https://stackoverflow.com/questions/3533470/how-to-forbid-git-commit-if-there-are-untracked-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!