Git diff 错误改动太多
Git diff too much wrong changes
我使用 windows 系统将我的更改推送到 git linux 服务器,其中用户使用 macOS 提交,这可能是 diff 更改无效的问题吗?不是更改的更改显示为已删除,后来以某种方式重新添加为新的。我正在使用 sublime,也尝试过具有相同行为的 netbeans...
Windows 和基于 *nix 的操作系统在文件中使用不同的行结束字符。在您的情况下,您要在文件中添加 Windows Carriage return 字符,而在 MacOSX 上它们将被删除。
在您的 Sublime 上,您可以更改保存时的行结束符以匹配 MacOSX 的行结束符。参见 is there a way to convert files line ending on saving。这样你就不会看到这些变化。
您还可以指示 git 使用 core.autocrlf
配置自动进行转换。参见 GitHub dealing with line endings
GitHub suggests 你应该确保在 git 处理的回购中只使用 \n 作为换行符。有一个自动转换的选项:
$ git config --global core.autocrlf true
当然,这里说的是crlf转lf,而你想crlf转lf。我希望这仍然有效……
然后转换您的文件:
# Remove everything from the index
$ git rm --cached -r .
# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add
# Commit
$ git commit -m "Fix CRLF"
core.autocrlf
Setting this variable to "true" is almost the same as setting the text
attribute to "auto" on all files except that text files are not
guaranteed to be normalized: files that contain CRLF in the repository
will not be touched. Use this setting if you want to have CRLF line
endings in your working directory even though the repository does not
have normalized line endings. This variable can be set to input, in
which case no output conversion is performed.
远程仓库混合了 cr/lf lineendings,以为是 unix,现在我只是设置原来的 lineendings 如果它再次发生。
我使用 windows 系统将我的更改推送到 git linux 服务器,其中用户使用 macOS 提交,这可能是 diff 更改无效的问题吗?不是更改的更改显示为已删除,后来以某种方式重新添加为新的。我正在使用 sublime,也尝试过具有相同行为的 netbeans...
Windows 和基于 *nix 的操作系统在文件中使用不同的行结束字符。在您的情况下,您要在文件中添加 Windows Carriage return 字符,而在 MacOSX 上它们将被删除。
在您的 Sublime 上,您可以更改保存时的行结束符以匹配 MacOSX 的行结束符。参见 is there a way to convert files line ending on saving。这样你就不会看到这些变化。
您还可以指示 git 使用 core.autocrlf
配置自动进行转换。参见 GitHub dealing with line endings
GitHub suggests 你应该确保在 git 处理的回购中只使用 \n 作为换行符。有一个自动转换的选项:
$ git config --global core.autocrlf true
当然,这里说的是crlf转lf,而你想crlf转lf。我希望这仍然有效……
然后转换您的文件:
# Remove everything from the index
$ git rm --cached -r .
# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add
# Commit
$ git commit -m "Fix CRLF"
core.autocrlf
Setting this variable to "true" is almost the same as setting the text attribute to "auto" on all files except that text files are not guaranteed to be normalized: files that contain CRLF in the repository will not be touched. Use this setting if you want to have CRLF line endings in your working directory even though the repository does not have normalized line endings. This variable can be set to input, in which case no output conversion is performed.
远程仓库混合了 cr/lf lineendings,以为是 unix,现在我只是设置原来的 lineendings 如果它再次发生。