Windows Git检测实际字节相同的已更改文件
我对git(通过TortoiseGit)有一个问题,它显示我的项目的一些文件被修改了,但它们实际上没有被修改。我通过创建存储库的一个新克隆对其进行了双重检查,并且在不接触它的情况下,我已经让git检测到新创建的工作副本中的“修改”文件。这很烦人,因为某些操作被阻止(因为这会覆盖我的“修改”文件),但我无法还原它们,删除+还原也不起作用。提交“更改”是可行的,但不是理想的解决方案 我在Windows上,使用的是Tortoisegit1.8.16.0和Git2.6.4。直接使用Windows Git检测实际字节相同的已更改文件,windows,git,git-submodules,git-subtree,Windows,Git,Git Submodules,Git Subtree,我对git(通过TortoiseGit)有一个问题,它显示我的项目的一些文件被修改了,但它们实际上没有被修改。我通过创建存储库的一个新克隆对其进行了双重检查,并且在不接触它的情况下,我已经让git检测到新创建的工作副本中的“修改”文件。这很烦人,因为某些操作被阻止(因为这会覆盖我的“修改”文件),但我无法还原它们,删除+还原也不起作用。提交“更改”是可行的,但不是理想的解决方案 我在Windows上,使用的是Tortoisegit1.8.16.0和Git2.6.4。直接使用git status也
git status
也会显示相同的文件被“修改”
这似乎只发生在我的项目的一个目录中,它以前是一个子模块,但我现在使用的是git子树。所以在某个时候,我完全删除了子模块(或者我认为是这样),并创建了一个子树
有人有同样的问题吗?我怎样才能一劳永逸地修好它?(即使在提交“更改”后,一段时间后,有时几周后,我会有其他文件,有时是相同的文件,开始显示相同的奇怪问题)
下面是其中一个文件的diff结果:git diff app.config
diff --git a/Ozytis.Common/Web/app.config b/Ozytis.Common/Web/app.config
index 3686aab..f559fe7 100644
--- a/Ozytis.Common/Web/app.config
+++ b/Ozytis.Common/Web/app.config
@@ -1,25 +1,25 @@
-<U+FEFF><?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <configSections>
- <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
- <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=ne
utral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
- </configSections>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
- <entityFramework>
- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
- <parameters>
- <parameter value="v11.0" />
- </parameters>
- </defaultConnectionFactory>
- <providers>
- <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
- </providers>
- </entityFramework>
+<U+FEFF><?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <configSections>
+ <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+ <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=ne
utral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+ </configSections>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+ <entityFramework>
+ <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+ <parameters>
+ <parameter value="v11.0" />
+ </parameters>
+ </defaultConnectionFactory>
+ <providers>
+ <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+ </providers>
+ </entityFramework>
</configuration>
\ No newline at end of file
diff--git a/Ozytis.Common/Web/app.config b/Ozytis.Common/Web/app.config
索引3686aab..f559fe7 100644
---a/Ozytis.Common/Web/app.config
+++b/Ozytis.Common/Web/app.config
@@ -1,25 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\文件末尾没有换行符
对于该文件,diff显示所有行都已修改。然而,我用一个十六进制编辑器检查了以前和当前版本的文件,换行符是相同的,事实上每个字节都是相同的
此外,一些文件显示只有几行不同(但同样,它们不是)。即使整个文件都有一致的换行信息。看起来这确实是一个换行问题(感谢user3159253和HBHB对此的评论) 看起来像是一个git bug,因为为什么它的报告文件是不同的,但是当你把它们放在你的机器上的时候,它会改变行尾,这样你就看不出有什么不同了?我认为,如果配置为无论如何都要更改行尾差异,则它不应显示行尾差异(不带
git status
,也不带git diff
)
另外,在提问之前,我已经尝试过更改core.autocrlf,但结果是我的项目包含了.gittributes,这才是真正的问题。该文件以*text
开头,然后将一些文件格式更改为二进制,并且优先于core.autocrlf。因为每个人都在为这个项目使用Windows,所以我将它改为*binary
(请参阅下面的更新),至少现在一切都清楚了。这使得git检测到更多的文件被更改(同样,git对此并不一致?),但这次我确实看到了行结尾的差异。我犯下了这些罪行,我希望这就是故事的结局
更新:
在.gittributes中使用*binary
也不起作用,因为现在git无法合并文本文件,因为他认为文本文件是二进制的。正确的版本是*-text
:
取消设置路径上的文本属性告诉Git在签入或签出时不要尝试任何行尾转换
这个解决方案可能并不理想,因为在刷新工作副本之后,所有文件都将具有unix样式的行结尾(我想这是git存储的)。因此,您必须将所有文件转换回windows行结尾(帮助),并做出一个大的承诺,这将是未来合并的一大难题(如果有的话).文件权限是否已更改?git diff显示了什么?@choroba
git diff app.config
diff--git a/Ozytis.Common/Web/app.config b/Ozytis.Common/Web/app.config索引3686aab..f559fe7 100644--a/Ozytis.Common/Web/app.config+++b/Ozytis.Common/Web/app.config@@@1,25+-[snip]+\n文件末尾没有换行符
PS:没有办法在注释中保留换行符?您不能在注释中保留LFs,但您可以在问题中添加git diff
输出content@youen这确实是一个行尾问题。检查并尝试不同的core.autocrlf
设置。您还可能需要在新的提交中强制修复行结束问题。