Git - 在已经提交的文件中不改变行尾 [英] Git - unchange line endings in already committed file

查看:111
本文介绍了Git - 在已经提交的文件中不改变行尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了.gitattributes,并告诉git不要为几个文件更改行尾。问题是,他们已经承诺。愚蠢的聪明的git现在不想撤消它所做的事情。删除和重新添加这些文件不会有帮助(它优化了更改)。现在,我必须手动重新复制这些文件,每当我从回购拉动。



我能做什么?报告这是一个错误,并等待修复?以某种方式删除提交对象强制git重新创建它们?后者似乎很难/危险。编辑:我发现这个 GitHub上不错的指南,用于从回购库中完全删除文件。问题是,我不想把它从整个历史中删除。我必须,还是只能为最后一次提交做?如果我为最后一次提交完成操作,Git会重新找到并重新优化吗? 我会重新解释现在我已经深入挖掘了一些问题(我原来的描述稍微偏离了一点),并解释了解决方法。



我的Windows机器上的问题文件有LF结尾。当我将它们推送到beanstalkapp.com时,它们保留了它们的LF结尾(与Git设置无关)。当我把它们拉到另一台Windows机器上时,它们变成了CRLF。我添加了.gitattributes将它们视为二进制文件,但是在另一台Win机器上拖出这个文件并没有让它检查出LF。



其他Win上的Git SHOULD当它检测到新的.gitattributes时,它们已经正确地重新检测它们,但没有。此外,删除一个提交,重新添加它们在下一个,但推动他们在1步骤,并在1步拉他们也无法工作。

我不得不拉他们都被删除的提交。然后当他们重新添加时,我不得不再次拉。这让另一台Win机器正确地检查了它们。
我没有尝试在另一台Win机器上删除它们并重置--hard,这个人建议可能会清除Git的大脑。



将写入邮件列表,了解拉动.gitattributes的行为。

I read up on .gitattributes and told git not to change line endings for a few files. Problem is, they're already committed. Stupid clever git now does not want to undo what it's done. Deleting and re-adding the files does not help (it optimizes out the change). Right now, I have to manually re-copy these files whenever I pull from the repo.

What can I do? Report this as a bug and wait for a fix? Somehow delete the commit objects to force git to re-create them? The latter seems difficult/dangerous.

EDIT: I found this nice guide on GitHub for completely deleting a file from a repo. Problem is, I don't really want to remove it from the entire history. Do I have to, or can I do it only for the last commit? If I do it for the last commit, will Git re-find and optimize again?

解决方案

I'll re-explain the problem now that I've dug deeper (my original description was slightly off), and explain the work-around.

My problem files on my Windows machine have LF endings. When I pushed them to beanstalkapp.com, they retained their LF endings (as to be expected regardless of Git settings). When I pulled them on another Windows machine, they got changed to CRLF. I added .gitattributes to treat them as binary, but pulling this file on the other Win machine did not get it to check them out as LF.

Git on other Win SHOULD have re-chcked them out properly when it detected the new .gitattributes, but didn't. Also, deleting in one commit, re-adding them in the next, BUT pushing them in 1 step and pulling them in 1 step did not work either.

I had to pull the commit where they're all deleted. Then I had to pull again when they're re-added. This got the other Win machine to check them out correctly. I did not try deleting them on the other Win machine and doing a reset --hard, which someone suggested might have also cleared Git's brains.

I'll write to the mailing list about what the behavior of pulling .gitattributes should be.

这篇关于Git - 在已经提交的文件中不改变行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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