Git 将未修改的文件显示为已修改

问题描述 投票:0回答:2

设置

  • git 版本 2.32.0.windows.1
  • TortoiseGit 2.13.0.1
  • git 配置-l
  • 比较工具:BeyondCompare
    http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
    http.sslbackend=openssl
    diff.astextplain.textconv=astextplain
    filter.lfs.clean=git-lfs clean -- %f
    filter.lfs.smudge=git-lfs smudge -- %f
    filter.lfs.process=git-lfs filter-process
    filter.lfs.required=true
    credential.helper=manager-core
    core.autocrlf=true
    core.fscache=true
    core.symlinks=false
    core.editor="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
    pull.rebase=false
    credential.https://dev.azure.com.usehttppath=true
    init.defaultbranch=master
    user.email=***
    user.name=***
    core.quotepath=false
    core.commitgraph=true
    core.longpaths=true
    receive.advertisepushoptions=true
    gc.writecommitgraph=true
    credential.helper=manager-core
    filter.lfs.process=git-lfs filter-process
    filter.lfs.required=true
    filter.lfs.clean=git-lfs clean -- %f
    filter.lfs.smudge=git-lfs smudge -- %f
    submodul.recurse=true
    core.bare=false
    core.repositoryformatversion=0
    core.filemode=false
    core.symlinks=false
    core.ignorecase=true
    core.logallrefupdates=true
    remote.origin.url=***
    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    branch.master.remote=origin
    branch.master.merge=refs/heads/master

历史

我们从 SVN 切换到 GIT,然后我们将编码从 Windows1252 转换为 UTF8。在这一点上一切看起来都很好,但我还是想提一下。这些更改已成功提交。

错误

git status
和 TortoiseGit 都列出了很多文件(可能是全部)已修改,但这些文件是二进制相同的...
git diff
将所有行显示为已删除,将完全相同的行显示为已添加。
git diff -w
仅列出非文本文件(jar)。
差异对我来说似乎有点奇怪,因为所有文件都完全相同(我比较了十六进制数据)。
由于所有内容都已修改,因此我无法拉取。我的同事有时也有类似的问题。

编辑: 我还注意到错误只发生在我们添加 .gitattributes 的提交之后。这包含这样的东西:

*.c     text diff=c
*.cpp   text diff=cpp
*.hpp   text diff=cpp
*.h     text diff=c

如果我注释掉这些行,所有修改都将消失。如果我在修改中评论那些行,它们仍然消失了。

尝试

  • git 重置 --hard
  • git 存储
  • 通过 TortoiseGit 还原

在这些尝试之后

git status
和 TortoiseGit 仍然将这些文件列为已修改...
如果我提交这些文件,这种奇怪的行为就会消失,但可能会重新出现在不同的分支中。
唯一改变的是文件的最后修改时间戳。时间戳更改为实际时间。

问题

为什么所有这些文件都被列为已修改?有没有我缺少的设置?

git tortoisegit
2个回答
0
投票

正如@torek 在评论中指出的那样:.gitattribute 文本设置导致了问题。我们提交了那些 modified 文件,之后一切顺利。


0
投票

工作解决方案

我和我的同事有同样的问题

找到了一个在我的电脑和我的同伴电脑上都能工作的解决方案。

在你的 git 文件夹中

键入以下命令中的第 1 条:

$ git config core.autocrlf false
$ git config core.filemode false

(您可能需要同时输入两个,鉴于您的情况,第一个最合适)

奖励: 如果此解决方案适用于您,并且您想在整个 PC(所有 git 文件夹)上执行此操作,只需在

--global
之后添加参数
git configure
。例如:
git config --global core.autocrlf false

© www.soinside.com 2019 - 2024. All rights reserved.