git 似乎对文件是否已更改感到困惑(使用 autocrlf=true 选项)

标签 git bash core.autocrlf

我在我的 git 配置中设置了这个规则:

autocrlf = true

这是为了避免我们的设计师(使用 mac)无法打开由我们的开发团队(他们使用 mac 和 linux 的组合)保存的文本文件的问题。特别是一个文件(最近创建的)导致了一个问题:git 认为没有什么可以提交,但不让我检查另一个分支。

$ git status
# On branch master
# Your branch is up-to-date with 'dreamhost/master'.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   script/resource_library/fix_mp4_moov.sh
#

$ git commit -a -m "line endings changed again"
warning: LF will be replaced by CRLF in script/resource_library/fix_mp4_moov.sh.
The file will have its original line endings in your working directory.
# On branch master
# Your branch is up-to-date with 'dreamhost/master'.
#
nothing to commit, working directory clean

$ git pull
Already up-to-date.

$ git push
Everything up-to-date

$ git checkout feature/my_classes_v2
error: Your local changes to the following files would be overwritten by checkout:
    script/resource_library/fix_mp4_moov.sh
Please, commit your changes or stash them before you can switch branches.
Aborting

那么,cmon git,它是否已更改?做好决定。在文件上使用 cat -v 不会显示任何特殊的行结束字符:

$ head -3 script/resource_library/fix_mp4_moov.sh | cat -v
#!/bin/bash

VIDEO_DIR=$1

谁能告诉我怎么弄清楚?谢谢,麦克斯

编辑 - 如果我进入 vim 中的文件并执行 set ff=mac,那么我可以将其提交并向上推送。但是,这对我来说是错误的——我无法运行它,因为 bash 没有正确解析 shebang 行。

编辑 2 - git diff 结果。

$ git diff script/resource_library/fix_mp4_moov.sh
warning: LF will be replaced by CRLF in script/resource_library/fix_mp4_moov.sh.
The file will have its original line endings in your working directory.

最佳答案

简单地设置 core.autocrlf=true 并不是 Elixir 。您所做的只是保持存储库中的所有数据(行尾不匹配)相同,但现在您已经向 Git promise 存储库中的数据具有规范化的行尾 \n

当然,这不是真的,因为存储库仍然存在与设置 core.autocrlf=true 之前相同的行尾不匹配。

您需要 normalize your line endings在每个人的理智的存储库中。

关于git 似乎对文件是否已更改感到困惑(使用 autocrlf=true 选项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27905309/

相关文章:

Git 克隆卡住了——端口被阻塞了?

linux - 匹配模式并删除模式之前的 3 行以及匹配的模式行

windows - 如何更改 git status 显示最终未提交的已修改文件的行为?

linux - linux 和 windows 之间行尾差异的 Git 问题

node.js - 为什么netbeans 8要安装未使用的cordova插件

node.js - 使用 npm 版本补丁时自定义提交消息

git - 我如何用 jgit 做相当于 “git remote update” 的操作?

linux - 停止 shell 脚本发送重复的电子邮件 - 使用文件标志

linux - 使用 linux bash 脚本清除存档文件

windows - Git core.safecrlf 对具有相同行尾的文件的不同行为