当我尝试添加一个在Windows上无效的文件名时,我可以让git警告我吗?

我正在Linux机器上开发。 有一次,我添加了一个文件“sin(x):2.tex”或类似的东西。 这给使用Windows系统的朋友造成了一些麻烦,并想克隆我的存储库。

我知道在Windows上比在Linux 上有更多无效的文件名 。 有没有可能使git警告我,如果我尝试添加这样一个无效的文件名到我的资料库?

你可以在这个要点中看到一个预先提交钩子的好例子,参考这个关于有效的Windows名称的答案

 # A hook script to check that the to-be-commited files are valid # filenames on a windows platform. # Sources: # - https://stackoverflow.com/a/62888 # - http://msdn.microsoft.com/en-us/library/aa365247.aspx # # To enable this hook, rename this file to "pre-commit", move it to ".git/hook" and make it executable 

它使用git diff

 git diff --cached --name-only --diff-filter=A -z $against 

请注意, pre-commit钩子是客户端钩子 ,这意味着它必须在所有用户的所有仓库中进行部署。
它可以被绕过(使用git commit --no-verify )。

另一种方法是设置pre-receive钩子( 服务器端钩子 ),这将阻止包括无效文件名的任何推送。