试图用 git filter-branch 修复行尾,但没有运气 [英] Trying to fix line-endings with git filter-branch, but having no luck

查看:23
本文介绍了试图用 git filter-branch 修复行尾,但没有运气的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被 git 的 Windows/Linux 行尾问题所困扰.通过 GitHub、MSysGit 和其他来源,似乎最好的解决方案是将本地存储库设置为使用 linux 样式的行结尾,但将 core.autocrlf 设置为 true.不幸的是,我做得不够早,所以现在每次我拉更改时,行尾都会被打断.

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

我已经在 Windows 上使用 MSysGit 和通过 Mac OS X 终端尝试过这个.

解决方案

gitattributes 现在记录另一种修复"或规范化项目中所有行尾的方法.这是它的要点:

$ echo "* text=auto" >.gitattributes$ git add --renormalize .$ git status # 显示将被规范化的文件$ git commit -m "引入行尾规范化"

<块引用>

如果有任何不应该被规范化显示在 git status 中,之前取消设置他们的文本属性运行 git add -u.

manual.pdf -text

相反,git 做的文本文件检测不到可以有归一化手动启用.

weirdchars.txt 文本

这利用了在 2018 年 1 月发布的 git v2.16.0 中添加的新 --renormalize 标志.对于旧版本的 git,还有一些步骤:

$ echo "* text=auto" >>.gitattributes$ rm .git/index # 删除索引强制git$ git reset #重新扫描工作目录$ git status # 显示将被规范化的文件$ git add -u$ git add .gitattributes$ git commit -m "引入行尾规范化"

I have been bitten by the Windows/Linux line-ending issue with git. It seems, via GitHub, MSysGit, and other sources, that the best solution is to have your local repos set to use linux-style line endings, but set core.autocrlf to true. Unfortunately, I didn't do this early enough, so now every time I pull changes the line endings are borked.

I thought I had found an answer here but I can't get it to work for me. My Linux command line knowledge is limited at best, so i am not even sure what the "xargs fromdos" line does in his script. I keep getting messages about no such file or directory existing, and when I manage to point it to an existing directory, it tells me I don't have permissions.

I've tried this with MSysGit on Windows and via the Mac OS X terminal.

解决方案

The git documentation for gitattributes now documents another approach for "fixing" or normalizing all the line endings in your project. Here's the gist of it:

$ echo "* text=auto" >.gitattributes
$ git add --renormalize .
$ git status        # Show files that will be normalized
$ git commit -m "Introduce end-of-line normalization"

If any files that should not be normalized show up in git status, unset their text attribute before running git add -u.

manual.pdf -text

Conversely, text files that git does not detect can have normalization enabled manually.

weirdchars.txt text

This leverages a new --renormalize flag added in git v2.16.0, released Jan 2018. For older versions of git, there are a few more steps:

$ echo "* text=auto" >>.gitattributes
$ rm .git/index     # Remove the index to force git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"

这篇关于试图用 git filter-branch 修复行尾,但没有运气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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