这就是我要做的:
$ git init /tmp/repo
$ echo -e "1\r\n2" > x.txt
$ hexdump x.txt
0000000 31 0d 0a 32
$ git config --local core.autocrlf false
$ git add x.txt
$ git commit -m 'test' x.txt
[master (root-commit) fe8c018] x.txt
1 file changed, 2 insertions(+)
create mode 100644 x.txt据我所知,回购中的文件现在是1\r\n2。现在,如果我签出这段代码,文件的内容应该是1\n2,对吗?但事实并非如此:
$ git config --global core.autocrlf true
$ git clone file:///tmp/repo r
$ cd r
$ hexdump x.txt
0000000 31 0d 0a 32为什么还是\r\n?是应该是 \n对吧?
$ git --version
git version 2.14.1发布于 2017-10-03 09:30:46
我们所做的是在回购的根目录中添加一个.gitattributes文件,如下所示:
* text eol=lf
*.ttf binary
*.woff binary
*.woff2 binary第一行是"catch all“,它将所有行尾设置为Unix样式--您可以省略eol位,也可以将其设置为crlf。这应该会捕获您的.txt文件。
这并不是说.gitattributes将优先于他们机器上的单个开发人员的git配置,这就是为什么它建议拥有一个--特别是当您跨平台工作的时候。
不幸的是,这从来没有起作用,从来没有弄清楚为什么:* -text
发布于 2017-10-03 07:37:37
我认为git不承认此文件为文本文件,而是将其视为二进制文件。autocrlf不影响二进制文件。
要将特定的文件或扩展名标记为文本,可以添加.gitattributes文件,在其中指定要作为文本处理的女巫文件,例如:
*.x text将告诉git将所有扩展名为“x”的文件作为文本处理,并应用autocrlf。
有关基属性的文档,请参阅
发布于 2017-10-15 14:05:12
作为git-config手册页,core.autocrlf选项用于将“LF”转换为“CRLF”。
$ git init /tmp/repo
Initialized empty Git repository in /private/tmp/repo/.git/
$ cd /tmp/repo
$ echo -ne "1\n2" > x.txt
$ hexdump x.txt
0000000 31 0a 32
0000003
$ git config --local core.autocrlf false
$ git add x.txt
$ git commit -m 'test' x.txt
[master (root-commit) 7ed185b] test
1 file changed, 2 insertions(+)
create mode 100644 x.txt
$ cd ..
$ git config --global core.autocrlf true
$ git clone file:///tmp/repo r
Cloning into 'r'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
$ cd r
$ hexdump x.txt
0000000 31 0d 0a 32
0000004https://stackoverflow.com/questions/46539254
复制相似问题