gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 10:35:52 27 4
gpt4 key购买 nike

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

我知道还有更多invalid file names on Windows比在Linux上。如果我尝试将这样一个无效的文件名添加到我的存储库,是否有可能让 git 警告我?

最佳答案

你可以看到一个很好的例子 pre-commit hook in this gist , 引用 this answer about valid Windows names

# 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 Hook 是 client-side hook ,这意味着它必须部署在所有用户的所有存储库中。
它可以被绕过(使用 git commit --no-verify)。

另一种方法是设置一个 pre-receive Hook ( server-side hook ),它将阻止任何推送,包括无效的文件名。

关于linux - 当我尝试添加一个文件名在 Windows 上无效的文件时,我可以让 git 警告我吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27183254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com