gpt4 book ai didi

git line endings - 不能存储,重置,现在不能 rebase over spurious line endings commit

转载 作者:IT王子 更新时间:2023-10-29 01:09:57 26 4
gpt4 key购买 nike

我有一个 repo 协议(protocol),我向它添加了一个 gitattributes 并且工作正常。我通过保管箱将其同步到另一台机器。当我在另一台机器上打开它时,一堆文件突然出现在未暂存区域作为总差异(所有文件都是一个巨大的差异,这意味着行尾差异) - 我的 crlf 结尾基本上是 .* text=auto 并且我在 Windows 上工作。我试图 stash 更改、重置分支等。最后我决定提交文件,然后进行一些其他提交,我想在行尾提交之前重新排序(和压缩)。当我尝试 rebase 时,我得到一个:

error: Your local changes to the following files would be overwritten by merge
# those same files
Please, commit your changes or stash them before you can merge.
Aborting
Could not apply 89b25b81fff1a1e7893319e123aaaca9c4162a95... <commit message>

当然 stash 是行不通的

这是一个错误吗?

相关:

EDIT 与机器无关 - 在同一台机器上,一些 (...) 操作只会使这些文件(它们在 .gitattributes 上作为文本)出现在“更改”部分。似乎存在的唯一解决方法是:

git rm --cached -r .
git reset --hard

小心使用

编辑:上面的黑客移动到别名状态:

[alias]
crlf = !git rm -r . --cached -q && git reset --hard

更新 2015.09.30:我在 NTFS 分区中有一个 git 存储库,我在双引导环境中使用 Windows 7 和 arch linux。当我关闭 Windows 并启动到 arch 时,两个文件 (html) 显示为总差异(行尾差异)。上述解决方法不起作用 - 除非您多次应用它并在两者之间刷新 gui...

我的.gitattributes:

* text=auto

*.py text diff=python
*.html text
.project text
*.pkl -text

# M$ files
*.bat text eol=crlf

# UNIX files
**/generate_second_post text eol=lf

# git files - have them with LF, as I edit them via the shell (echo etc)
*.gitignore text eol=lf
*.gitattributes text eol=lf

注意:linux 允许我提交、切换分支等但不会让我 rebase - 而且这些差异总是出现在 gitk/git gui 中。

2018/12/14 移至 mac,我的解决方法不再有效。我向 git 邮件列表发布了一条消息:https://marc.info/?l=git&m=154482149623324&w=2

希望这会引起一些注意

$ git --version
git version 2.19.2

最佳答案

感谢 Torsten Bögershausen,5 年后终于有了一个完整的答案。

调试这种 eol 情况的方法是使用 --eol switch to git ls-files 进行调查。由 Torsten Bögershausen 添加。事实证明,有问题的文件是使用 CRLF 提交的,而后来添加的 .gitattributes 文件为这些文件指定了 text。结果in an "illegal state" .对于旧提交,无需执行任何操作。

应该做的是git add --renormalize .所以文件添加了正确的 (lf) 行尾,然后重置——很难在工作树中包含这些行尾。

现在这对旧的提交没有帮助,但是(处于这种非法状态的提交,所以在文件之间提交了错误的行尾和 gitattributes 提交) - 检查那些可能会导致那些不可重置的更改. answer 提供了此修复程序通过@iKlsR:

$ cat .git/info/attributes
"Mopy/Docs/Bash Readme Template.html" -text

原因是that :

When deciding what attributes are assigned to a path, Git consults $GIT_DIR/info/attributes file (which has the highest precedence), .gitattributes file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree [ect]

(强调我的)

请务必在 after you renormalize 添加行,否则文件将不会添加到 renormalize 提交中!

关于git line endings - 不能存储,重置,现在不能 rebase over spurious line endings commit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21122094/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com