-1

I have a git repository that for some reason is showing local changes I cannot revert. From a freshly cloned repo I see one configuration file changes with the following diff from 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

when I run git reset or git checkout, nothing changes. If I run git reset --hard I get the following results

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

Which are showing that the added lines, and the deleted lines have switched. Running git reset --hard will cause these two sections of code to switch back and forth between being added and being removed. What am I doing incorrectly?

Alexander Burke
  • 534
  • 7
  • 22

2 Answers2

1
git reset --hard HEAD^

Here HEAD - the commit I'm currently sitting on; HEAD^- commit's parent; This will remove your changes locally

Cyclotron3x3
  • 2,188
  • 23
  • 40
  • How does this explain OP's problem? – Leon Sep 26 '16 at 17:02
  • git reset --hard changes, at minimum, where the current branch (HEAD) is pointing.Changing head to explicitly one commit back make sure the directory is clean again. The changes won't stay in your working tree so doing a git status command will tell you that you don't have any changes in your repository. – Cyclotron3x3 Sep 26 '16 at 17:11
  • `git reset --hard` without any argument doesn't change HEAD. It only resets the index and the tracked files in the working tree to their state corresponding to HEAD. What's your explanation for the alternating diff output after running `git reset --hard`? – Leon Sep 26 '16 at 17:21
  • I'm not sure about that behavior(not commonly observed ) but moving a head behind explicitly will clean the directory thereby overcoming alternating diff. But I can understand your concern too. – Cyclotron3x3 Sep 26 '16 at 17:27
  • Regardless of why the diff ouput is alternating, I am getting the error "fatal: ambiguous argument 'HEAD" when running that command? Could this be related to my issue? – Alexander Burke Sep 26 '16 at 17:30
  • @AlexanderBurke Are you sure that the error says "HEAD" and not "HEAD^"? – Code-Apprentice Sep 26 '16 at 17:33
  • what is the output of this command `git show-ref --heads -s` or git show HEAD – Cyclotron3x3 Sep 26 '16 at 17:33
  • @Cyclotron3x3 it shows "commit 3a690a041f52e9fc6ccccadb00e786ba2012fc7a Merge: 79358cb 9596997" followed by the name and commit message of the last commit, which was a merge by my teammate – Alexander Burke Sep 26 '16 at 17:35
  • @Code-Apprentice it says this exactly "fatal: ambiguous argument 'HEAD ': unknown revision or path not in the working tree." – Alexander Burke Sep 26 '16 at 17:53
  • seems like you have only one commit in history.Since its a fresh cloned org. What you can do is you can set it back to origin by `git fetch origin, git reset --hard origin/master` or `git reset --hard ` – Cyclotron3x3 Sep 26 '16 at 17:53
  • Did you type the apostrophe in the command? – Code-Apprentice Sep 26 '16 at 17:55
  • @Code-Apprentice, i did not – Alexander Burke Sep 26 '16 at 18:09
  • Check if you can reset back to origin from above commands – Cyclotron3x3 Sep 26 '16 at 18:16
  • I was not able to, the issue was from two file with the same name, but a different case. I posted an answer for it – Alexander Burke Sep 27 '16 at 14:45
1

Turns out the problem was that at some point someone had committed an app.Config and someone else had committed App.config, which you can see in the output above. Git can handle this because Linux has case sensitive files, but Windows does not. I discovered the below answer to this, and the fix, from this question

git mv -f app.config App.config
git commit -m 'fix case'

to prevent the issue from occuring again

git config core.ignorecase true

Git status shows file twice but different case

Community
  • 1
  • 1
Alexander Burke
  • 534
  • 7
  • 22