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

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 version control history “modifed files” are empty in Xcode 8.1
  • Have JIRA send mails to watchers on commit from Stash on a ticket
  • Git remove files on server not present on local
  • Is it possible to include a file in your .gitconfig
  • Multiple projects in one git repo?
  • How to import and run project, in Android Studio 1.1, from Github?
  • >> 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?

  • GitHub to Heroku Commit Error
  • Can't run wave engine app in my visualstudio
  • How does Github for Mac synchronize?
  • Understanding detached HEAD in git
  • Rollback changes for only one of commited files
  • Tell Git forks to forget about tracking a file that was tracked before but still keeping it in upstream
  • One Solution collect form web for “Why does Git insist that a file has been modified even after a `git checkout –`?”

    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

    Git Baby is a git and github fan, let's start git clone.