我在git config中设置了这个规则:
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
谁能告诉我如何设置这个?谢谢,Max
编辑 - 如果我在vim中进入文件并执行set ff=mac
,那么我可以将其提交并推送它。但是,这打破了它 - 我无法运行它,因为bb线没有正确解析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.
答案 0 :(得分:3)
简单地设置core.autocrlf=true
不是一个神奇的子弹。您所做的就是保持存储库中的所有数据(行结尾不匹配)相同,但现在您已向Git承诺存储库中的数据已标准化\n
的行结尾
当然,事实并非如此,因为在设置core.autocrlf=true
之前,存储库仍然具有相同的行结尾不匹配。
您需要在存储库中normalize your line endings,以确保每个人的理智。