git - 尝试使用 git filter-branch 修复行尾,但没有运气

标签 git newline msysgit line-endings

我一直被 git 的 Windows/Linux 行结束问题困扰。看来,通过 GitHub、MSysGit 和其他来源,最好的解决方案是将您的本地存储库设置为使用 linux 样式的行尾,但将 core.autocrlf 设置为 true。不幸的是,我没有及早做这件事,所以现在每次我 pull 更改时,行尾都被打乱了。

我以为我找到了答案here但我无法让它为我工作。我的 Linux 命令行知识充其量是有限的,所以我什至不确定“xargs fromdos”行在他的脚本中做了什么。我不断收到有关不存在此类文件或目录的消息,当我设法将其指向现有目录时,它告诉我我没有权限。

我已经在 Windows 和 Mac OS X 终端上使用 MSysGit 进行了尝试。

最佳答案

解决此问题的最简单方法是进行一次修复所有行尾的提交。假设您没有任何修改过的文件,那么您可以按如下方式执行此操作。

# From the root of your repository remove everything from the index
git rm --cached -r .

# Change the autocrlf setting of the repository (you may want 
#  to use true on windows):
git config core.autocrlf input

# 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 "Fixed crlf issue"

# If you're doing this on a Unix/Mac OSX clone then optionally remove
# the working tree and re-check everything out with the correct line endings.
git ls-files -z | xargs -0 rm
git checkout .

关于git - 尝试使用 git filter-branch 修复行尾,但没有运气,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1510798/

相关文章:

bash - 找不到 `msbuild` 命令,但 `msbuild.exe` 工作正常

git - 如果我已经有 Cygwin,我真的需要 MsysGit 吗?

git - 直接提交到裸存储库

Python 在写入文件时修改换行符

java - 文本文件io和换行符

bash - 在 bash 中,如何强制刷新打印到终端的不完整行

git - git创建分支时出错

git - git log -p 忽略文件

git - 如何截断 git log 中的字段 --pretty

git - oh-my-zsh 慢,但只适用于某些 Git 仓库