Why does Git insist that a file has been modified even after a `git checkout --`?

Go To StackoverFlow.com

4

I made a change to a couple of files locally, without committing them. git status shows:

>> git status
# On branch feature-ravendb
# Your branch is ahead of 'origin/feature-ravendb' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/PowerShellRunner.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

I want to discard the changes to those files. I tried following the instructions:

>> git checkout -- .\source\Octopus.Tentacle\Integration\PowerShell\IPowerShell.cs

The command has no output. Now I run git status again:

>> git status
# On branch feature-ravendb
# Your branch is ahead of 'origin/feature-ravendb' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/PowerShellRunner.c
#
no changes added to commit (use "git add" and/or "git commit -a")

Hmm, it's pretty convinced that the file has changed. And git diff <file> seems to think that the whole file has changed, even though it hasn't:

diff --git a/source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs b/source/Octo
--- a/source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
+++ b/source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
@@ -1,9 +1,9 @@
-<EF><BB><BF>using System;
-
-namespace Octopus.Tentacle.Integration.PowerShell
-{
-    public interface IPowerShell
-    {
-        PowerShellExecutionResult Execute(PowerShellArguments arguments);
-    }
+<EF><BB><BF>using System;
+
+namespace Octopus.Tentacle.Integration.PowerShell
+{
+    public interface IPowerShell
+    {
+        PowerShellExecutionResult Execute(PowerShellArguments arguments);
+    }
 }
\ No newline at end of file

How do I convince git that I really, really haven't changed the file and don't want to commit it?

Edit: The following commands also have no effect on these modifications:

  • git checkout -- .
  • git checkout -f
  • git reset --soft
  • git reset --hard

Edit 2: Reverting back to an older revision, stashing my changes, then clearing the stash eventually worked. It seems like my line endings are conflicting but I don't know why:

  • I have core.autocrlf set to true
  • I have a .gitattributes file with the line *.cs text

Shouldn't this be enough?

2012-04-04 19:23
by Paul Stovell
Tried to use forward slashes in path - kirilloid 2012-04-04 19:25
Just tried now, but it didn't make a differenc - Paul Stovell 2012-04-04 19:26
It might be a line-ending issue: http://help.github.com/line-endings - friism 2012-04-04 19:27
git config core.autocrlf is true and I have a .gitattributes that makes .cs files text. Also it only affects these two files (where I made a change and reverted), not the whole repo - Paul Stovell 2012-04-04 19:32
I may suggest git checkout -f and if it won't work then git reset --soft, but I'm not completely sure that the latter is safe - kirilloid 2012-04-04 19:35
I just tried git checkout -f, git reset --soft and even git reset --hard and the files are still modified. Is there a git reset --please-git-even-vss-can-do-this option? : - Paul Stovell 2012-04-04 19:37
Try deleting the files, then do a git reset --hardjeffora 2012-04-04 22:40


4

I had a core.autocrlf is false, but recently changed to true and also apply gitattributes changes for .net. After that, in many repositories, when you try to pull, I began to receive reports on the changes which not exist, and are also unable to roll back. In the end, I went back to core.autocrlf is false

2012-04-04 19:51
by andrii.chumak
Did you keep the .gitattributes - Paul Stovell 2012-04-04 21:09
No, also remove. I think it might work if you make a clean repository clone again after autocrlf and gitattributes changes. But I have not tried it - andrii.chumak 2012-04-04 21:26
Ads