【问题标题】:Why are there cr characters in the output of a diff when there are none in the input?当输入中没有字符时,为什么 diff 的输出中有 cr 字符?
【发布时间】:2013-12-13 20:47:24
【问题描述】:

我在 linux 机器上有一个裸 git 存储库,我正在从 Windows 机器推送到它,并使用 linux 机器上的 post-receive 挂钩将其签出到本地文件夹。

在 Windows 机器上,我有 core.autocrlf=true,在 linux 机器上是 core.autocrlf=input。我还有一个 .gitattributes 文件,其内容如下:

* text=auto
*.csv text

在 linux 机器上,我将存储库中的 csv 文件(由 Windows 机器生成)与 linux 机器生成的非存储库文件进行比较:

diff -iw -U0 repofile.csv localfile.csv > out.txt

例如,当我在 vi 中分别打开 repofile.csv 和 localfile.csv 时,两个文件都没有 CR 字符,这正是我想要的。但是,当我打开 out.txt 时,看哪,每行末尾都有 CR 字符,涉及 repofile.csv 中的一行。

什么给了?当两个输入文件都没有 CR 字符时,为什么 CR 字符会出现在 diff 的输出中,我对此完全感到困惑。

【问题讨论】:

    标签: git diff newline


    【解决方案1】:

    确保两台服务器上都有 core.autocrlf is false:您不希望 Git 自动修改任何文件,除非您明确指示 Git(通过 core.eol .gitattributes directives) .

    由于core.autocrlf 覆盖core.eol,这可以解释您一直看到的CR。

    【讨论】:

    • 这似乎无法解决问题。我仍然在任何一个 diff 文件中都看不到 CR,但我确实在 diff 输出中看到了 CR。
    猜你喜欢
    • 2020-01-22
    • 2020-09-08
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    相关资源
    最近更新 更多