LussacZheng / video-downloader-deploy

Video Downloaders (you-get, youtube-dl, lux) One-Click Deployment Batch. || 视频下载器 (you-get, youtube-dl, lux) 一键配置脚本。
549 stars 99 forks source link

Line endings problem of Git again / Git换行符问题 #4

Closed LussacZheng closed 5 years ago

LussacZheng commented 5 years ago

English translation is NOT provided for this record. Please translate it by yourself.

LussacZheng commented 5 years ago

A record of fixing "Line endings problem of Git"

Keywords: line endings, git, batch, gitattributes


Issue

执行 Deploy.bat -> [6] 高级设置 -> [1] 选择语言 后,脚本提示:

执行系统找不到指定的批处理标签 - Config_Language

之后再重新打开脚本,菜单选项文本全部无法显示。且 res\deploy.settings 文件内容被清空。
高级设置 中的其他选项没有出现类似问题。


Cause

脚本的 高级设置 功能在本地测试时没有发现问题,只有通过 GitHub 项目主页 "Download ZIP" 下载的脚本会出现该问题。经分析,此 Bug 与 Issue #2 属于同一种情况。为 Git的换行符问题

Config_Language 方法属于 res\scripts\Config.bat ,而 Config.bat 的换行符(Line endings)为 LF 并非 CRLF。且 Config_Language 方法中引用了 res\scripts\lang_*.bat ,这就涉及到 “LF 作为换行符的 .bat 批处理文件,包含中文字符时会出现不可预期的错误” 的问题。

而换行符同样被错误地设置为 LF 的还有: (res\scripts\ 目录下的) DoDeploy.bat , GenerateDownloadBatch.bat , GenerateWgetOptions.bat , Log.bat , SourcesSelector.bat ,和(res\dev\ 目录下的) SourcesListsDiff.bat 。加上 Config.bat ,总计7个文件的换行符被错误地设置为 LF

除了 Config.bat ,其他脚本并不涉及到中文字符(Chinese character),因此能够正常运行,并没有表现出明显的错误。


Solution

依照 Reference ,记录具体解决办法和操作步骤如下,以防下次出现相同的问题。

  1. 首先打开 Git Bash ,确保 git config --global core.autocrlftrue
  2. 删除(或移动并备份)本地 Git 储存库,重新 git clone
  3. 打开新的本地 Git 仓库文件夹,(可选)将 .gitattributes 中过时的 -crlf 属性修改为等价的 -text
  4. 暂存更改,然后显示所有需要改变换行符的文件(7个):

    $ git add . -u
    
    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            modified:   .gitattributes
            modified:   res/dev/SourcesListsDiff.bat
            modified:   res/scripts/Config.bat
            modified:   res/scripts/DoDeploy.bat
            modified:   res/scripts/GenerateDownloadBatch.bat
            modified:   res/scripts/GenerateWgetOptions.bat
            modified:   res/scripts/Log.bat
            modified:   res/scripts/SourcesSelector.bat
  5. (可选)让当前 Git 项目启用签名验证:
    $ git config commit.gpgsign true
  6. 提交并推送:

    $ git commit -m "Fix: Line endings problem of Git again"
    [master 9b1f4a2] Fix: Line endings problem of Git again
     8 files changed, 668 insertions(+), 663 deletions(-)
     rewrite .gitattributes (64%)
    
    $ git push origin master

Reference