为什么 git 重置没有删除我的本地更改?
Why are my local changes not being removed by git reset?
我有一个 git 存储库,出于某种原因,它显示了我无法还原的本地更改。从一个新克隆的 repo 中,我看到一个配置文件发生了以下变化,来自 git diff
C:\Projects\NewUI>git diff
diff --git a/EPFR.CountryFlows.Tests/app.config b/EPFR.CountryFlows.Tests/app.config
index d7256aa..7e1d79c 100644
--- a/EPFR.CountryFlows.Tests/app.config
+++ b/EPFR.CountryFlows.Tests/app.config
@@ -1,11 +1,17 @@
<U+FEFF><?xml version="1.0" encoding="utf-8"?>
<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
+ <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=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+ </configSections>
+ <entityFramework>
+ <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+ <parameters>
+ <parameter value="mssqllocaldb" />
+ </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
当我 运行 git reset
或 git checkout
时,没有任何变化。如果我 run git reset --hard
我得到以下结果
C:\Projects\NewUI>git diff
diff --git a/EPFR.CountryFlows.Tests/App.config b/EPFR.CountryFlows.Tests/App.config
index 7e1d79c..d7256aa 100644
--- a/EPFR.CountryFlows.Tests/App.config
+++ b/EPFR.CountryFlows.Tests/App.config
@@ -1,17 +1,11 @@
<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=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
- </configSections>
- <entityFramework>
- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
- <parameters>
- <parameter value="mssqllocaldb" />
- </parameters>
- </defaultConnectionFactory>
- <providers>
- <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
- </providers>
- </entityFramework>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
</configuration>
\ No newline at end of file
其中显示添加的行和删除的行已经切换。 运行 git reset --hard
会导致这两段代码在添加和删除之间来回切换。我做错了什么?
git reset --hard HEAD^
Here HEAD - the commit I'm currently sitting on; HEAD^- commit's parent; This will remove your changes locally
原来问题是在某个时候有人提交了 app.Config 而其他人提交了 App.config,您可以在上面的输出中看到。 Git 可以处理这个,因为 Linux 有区分大小写的文件,但 Windows 没有。我从这个问题
中发现了以下答案和修复方法
git mv -f app.config App.config
git commit -m 'fix case'
防止问题再次发生
git config core.ignorecase true
Git status shows file twice but different case
我有一个 git 存储库,出于某种原因,它显示了我无法还原的本地更改。从一个新克隆的 repo 中,我看到一个配置文件发生了以下变化,来自 git diff
C:\Projects\NewUI>git diff
diff --git a/EPFR.CountryFlows.Tests/app.config b/EPFR.CountryFlows.Tests/app.config
index d7256aa..7e1d79c 100644
--- a/EPFR.CountryFlows.Tests/app.config
+++ b/EPFR.CountryFlows.Tests/app.config
@@ -1,11 +1,17 @@
<U+FEFF><?xml version="1.0" encoding="utf-8"?>
<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
+ <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=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+ </configSections>
+ <entityFramework>
+ <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+ <parameters>
+ <parameter value="mssqllocaldb" />
+ </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
当我 运行 git reset
或 git checkout
时,没有任何变化。如果我 run git reset --hard
我得到以下结果
C:\Projects\NewUI>git diff
diff --git a/EPFR.CountryFlows.Tests/App.config b/EPFR.CountryFlows.Tests/App.config
index 7e1d79c..d7256aa 100644
--- a/EPFR.CountryFlows.Tests/App.config
+++ b/EPFR.CountryFlows.Tests/App.config
@@ -1,17 +1,11 @@
<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=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
- </configSections>
- <entityFramework>
- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
- <parameters>
- <parameter value="mssqllocaldb" />
- </parameters>
- </defaultConnectionFactory>
- <providers>
- <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
- </providers>
- </entityFramework>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
</configuration>
\ No newline at end of file
其中显示添加的行和删除的行已经切换。 运行 git reset --hard
会导致这两段代码在添加和删除之间来回切换。我做错了什么?
git reset --hard HEAD^
Here HEAD - the commit I'm currently sitting on; HEAD^- commit's parent; This will remove your changes locally
原来问题是在某个时候有人提交了 app.Config 而其他人提交了 App.config,您可以在上面的输出中看到。 Git 可以处理这个,因为 Linux 有区分大小写的文件,但 Windows 没有。我从这个问题
中发现了以下答案和修复方法git mv -f app.config App.config
git commit -m 'fix case'
防止问题再次发生
git config core.ignorecase true
Git status shows file twice but different case