禁用git EOL转换 [英] Disable git EOL Conversions

查看:123
本文介绍了禁用git EOL转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让git不更改任何操作的任何行尾.不幸的是,这似乎无关紧要.我将其简化为以下测试案例,该案例具有我发现的多种禁用此行为的机制.

I am trying to get git to not change any line endings whatsoever for any operation. Unfortunately, it seems to do so not matter what. I have reduced it down to the following test case, which has as many different mechanisms for disabling this behavior as I could find.

  • 从两台计算机开始(Windows计算机= A,Linux计算机= B)
  • 在两台计算机上:git config --global core.autocrlf false
  • 在两台计算机上:git config --global core.eol crlf(以防万一)
  • Begin with two machines (Windows computer = A, Linux computer = B)
  • On both machines: git config --global core.autocrlf false
  • On both machines: git config --global core.eol crlf (just in case)
  • 在A上建立新的存储库.从一个空文件夹中:
    • git init --shared(然后取消隐藏创建的.git目录)
    • 在存储库中新建文件.gitignore
    • 在存储库中用单行创建新文件.gitattributes:* -text
    • git add .,然后按git commit -m "initial commit"可以解决,例如.
    • git branch master_recv
    • 添加遥控器
    • Make new repository on A. From an empty folder:
      • git init --shared (then unhide the created .git directory)
      • Make a new file .gitignore in the repository
      • Make a new file .gitattributes in the repository with the single line: * -text
      • git add ., then git commit -m "initial commit" to work around, e.g. this.
      • git branch master_recv
      • Add remotes
      • SCP将整个目录保存到计算机B
      • 添加包含CRLF的新文件new file
      • 提交:git add -A,然后是git commit -m "<something>"
      • 请注意,B的document.txt和B的new file仍然都包含CRLF
      • SCP the whole directory to computer B
      • Add a new file new file containing CRLF
      • Commit: git add -A, then git commit -m "<something>"
      • Note that B's document.txt and B's new file both still contain CRLF
      • 将B的主人拉到A:git pull <remote> master:master_recv
      • A的document.txt已更改为LF.添加的文件new file也包含LF.
      • Pull B's master to A: git pull <remote> master:master_recv
      • A's document.txt has changed to LF. The added file new file also contains LF.

      如果B是Windows计算机,则不会发生此问题.

      The problem does not occur if B is a Windows machine.

      推荐答案

      我知道了. SCP程序似乎正在转换行尾.当我尝试故意制作一个带有LF结尾的文件,然后观察到下载时它显示为CRLF时,我注意到了这一点.

      I figured it out. It seems that the SCP program was converting the line endings. I noticed this when I tried deliberately making a file with LF endings and then observing that it appeared as CRLF when downloaded.

      因为这是我的解决方案,所以我接受此答案,但是将来的人们也应该参考其他答案以获取更通用的解决方案.

      Since this was the solution for me, I'm accepting this answer, but people of the future should also refer to the other answers for a more general solution.

      这篇关于禁用git EOL转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆