Nry*_*an6 8 windows git filenames
我正在使用git进行版本控制的共享项目.当我的伙伴在Unix上时,我在Windows上.
我的搭档用一些文件命名<file1>.txt.当我试图拉他们不接受为这些文件<和>适用于Windows无效字符.这很好,我不需要触摸文件.但是,它们会被添加到我的提交中作为已删除.所以,如果我推,那么我将删除这些我不想做的文件.
我无法使用,git reset --hard因为它为每个"已删除"文件找到了无效路径.
有没有办法从我的提交中排除这些文件?我已经尝试添加<file1>到我的.git/info/exclude但是没有用.
您需要让您的合作伙伴将名称更改为在 Windows 上也有效的名称。在他们重命名后,我要做的是:
git reset --hard <commit>在<commit>添加文件之前运行where是任何提交。git pull以获得最新版本(文件被重命名的地方)。然后,这应该获得更新的修订版,其中文件未在此命名为 Windows,非法方式,并且它们不会被操作系统从 git 下删除(或从未创建):)
PS 我知道这是一个老问题,但我最近遇到了这个问题,所以希望我得到的解决方案也可以帮助其他人。
编辑:
为避免这种情况再次发生,您的合作伙伴可以添加一个预提交挂钩,以阻止他们提交名称在 Windows 上不允许的文件。pre-commit.sample 中经常有一个示例/示例。我在过去稍微改变了一点,最终得到了类似的东西:
# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
echo $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C)
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ !#-)+-.0-9;=@-[]-{}~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi
Run Code Online (Sandbox Code Playgroud)
该'[ !#-)+-.0-9;=@-[]-{}~]\0'位是重要的组成部分,我已经改变了一点点。它定义了所有允许的字符范围,示例中只禁止“非 ascii”字符(这是顶部的注释所说的),但也有不允许在 Windows 上的文件名中使用的 ascii 字符(例如作为?和:)。
所有允许的字符都被删除,如果还有任何东西 ( wc -c != 0) 它会出错。它可能有点难以阅读,因为您看不到任何不允许的字符。如果您在阅读或编辑时有一个要查看的字符范围列表,这会有所帮助。