为什么"git status"在二进制文件未更改且文件模式相同时将其显示为已修改的二进制文件 [英] Why does 'git status' show binary file as modified when it's not and file modes are the same

查看:261
本文介绍了为什么"git status"在二进制文件未更改且文件模式相同时将其显示为已修改的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu 14.04 linux上的git repo中添加了一些二进制文件,将这些文件推送到GitHub远程服务器,然后将它们拉到OS X El Capitan和Windows 10上的现有克隆中.这些文件即使没有被修改也被修改.即使在git reset --hardgit checkout之后,它仍继续显示它们已更改.

I added some binary files to a git repo on Ubuntu 14.04 linux, pushed those files to a GitHub remote then pulled them to existing clones on OS X El Capitan and Windows 10. git status on OS X and Windows shows some of these files as modified even though they have not been touched. It continues to shown them as changed even after git reset --hard and git checkout.

注意,我正在对这些文件使用Git LFS(大文件存储).

Note, I am using Git LFS (Large File Storage) with these files.

这是OS X上git diff的输出,其中只有1个文件显示为已修改:

Here is the output from git diff on OS X where only 1 file shows as modified:

Marks-MacBook:KTX mark$ git diff other_lib/linux/Release-x64/libSDL2main.a
diff --git a/other_lib/linux/Release-x64/libSDL2main.a b/other_lib/linux/Release-x64/libSDL2main.a
index 4202f6f..2797199 100644
Binary files a/other_lib/linux/Release-x64/libSDL2main.a and b/other_lib/linux/Release-x64/libSDL2main.a differ

Marks-MacBook:KTX mark$ git diff --raw other_lib/linux/Release-x64/libSDL2main.a
:100644 100644 4202f6f... 0000000... M  other_lib/linux/Release-x64/libSDL2main.a

文件在.gitattributes中标记为-text,因此EOL标记应该没有任何问题.还有什么可能导致不同的sha1结果和git diff报告的二进制文件不同?

The files are marked -text in .gitattributes so there should not be any issues with EOL markers. What else could cause the different sha1 results and git diff to report the binary files differ?

我为*.a文件添加了diff=bin.gitattributes,其中bin使用textconv = hexdump -v -C.此后,git diff没有报告差异,但是git status仍显示文件已修改.

I added a diff=bin to .gitattributes for *.a files where bin uses textconv = hexdump -v -C. After this git diff reports no differences but git status still shows the files as modified.

作为一项附加测试,我将原始.a文件从linux复制到OS X,并使用diff将其与git工作树中的副本进行比较.它们是相同的. linux repo克隆上的git status报告我复制的工作树文件未修改.

As an additional test, I copied the original .a file from linux to OS X and used diff to compare it with the copy in my git working tree. They are identical. git status on the linux repo clone reports the working tree file, that I copied, is unmodified.

有什么建议吗?

以下内容不再适用;仓库已按照我的回答中所述进行了修复.

您可以自己尝试.回购协议分支位于GitHub上的 https://github.com/KhronosGroup/KTX/tree/incoming.在OS X上显示问题的文件为other_lib/linux/Release-x64/libSDL2main.a. other_lib/linux下的任何其他.a文件都没有问题.

You can try for yourselves. The repo & branch is on GitHub at https://github.com/KhronosGroup/KTX/tree/incoming. The file showing the problem on OS X is other_lib/linux/Release-x64/libSDL2main.a. There is no problem with any of the other .a files under other_lib/linux.

在Windows上,其他文件显示为已修改,包括Linux上的一些符号链接.由于它比较简单,我现在想集中讨论OS X的情况.

On Windows a few more files are shown as modified including some that are symbolic links on Linux. I want to concentrate on the OS X case for now since it is simpler.

推荐答案

我发现了问题所在.它与Linux主机上的配置相同.感谢 Edward Thomson 促使我看看git-lfs配置.

I figured out the problem. It was with the configuration on the Linux host. Thanks to Edward Thomson for prompting me to look at the git-lfs configurations.

在Linux主机上运行git lfs init,删除&将二进制文件重新添加到该仓库中并推送到远程已解决了该问题.要将更新拉到OS X和Windows主机,我必须在它们上运行git reset --hard,以重新设置为没有问题文件的提交.

Running git lfs init on the Linux host, deleting & re-adding the binary files to the repo there and pushing to the remote has fixed the problem. To pull the update to the OS X and Windows hosts, I had to run git reset --hard on them to reset back to a commit without the offending files.

我还没有运行git lfs init,因为我认为这一步将是apt-get install运行的脚本的一部分.这意味着文件实际上没有存储在LFS中,因为Linux主机上的污迹和清理过滤器是无操作的,但是.gitattributes文件导致OS X和Windows主机在结帐时运行LFS污迹过滤器.

I had not run git lfs init, having thought that this step would be part of the scripts run by apt-get install. This meant that the files were not actually stored in LFS, because the smudge and clean filters on the Linux host were no-ops, but the .gitattributes file was causing the OS X and Windows hosts to run the LFS smudge filter on checkout.

这篇关于为什么"git status"在二进制文件未更改且文件模式相同时将其显示为已修改的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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