How can i remove 'Changes not staged for commit'? in git

When I do ‘git status’, I get

% git status
# Not currently on any branch.
# 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/WebKit/win/WebKit.vcproj/WebKitApple.vsprops
#       modified:   Source/WebKit/win/WebKit.vcproj/WebKitDirectX.vsprops

But after I did ‘% git checkout — Source/WebKit/win/WebKit.vcproj/WebKitApple.vsprops’, I see get the same:

  • How to change orientation in tig status view
  • Why is there no git commit -A -m? It must have been deliberately omitted, but why?
  • Very weird tracking of a file using git
  • How do I edit after squashing while doing an interactive rebase?
  • Copying only files from git tag
  • Selective merge with Git?
  • % git checkout -- Source/WebKit/win/WebKit.vcproj/WebKitApple.vsprops
    % git status
    # Not currently on any branch.
    # 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/WebKit/win/WebKit.vcproj/WebKitApple.vsprops
    #       modified:   Source/WebKit/win/WebKit.vcproj/WebKitDirectX.vsprops
    #
    

    How can I remove those “changes not staged for commit”?

    I have even tried ‘git stash’, still some how those changes stuck around.

    I have do a ‘git diff’. And this is the result, I don’t see ^M:
    And I have looked at ‘.gitconfig’, I don’t have ‘autoctrl

    % git diff       
    diff --git a/Source/WebKit/win/WebKit.vcproj/WebKitApple.vsprops b/Source/WebKit/win/WebKit.vcproj/WebKitApple.vsprops
    index 2ea7a51..9643739 100644
    --- a/Source/WebKit/win/WebKit.vcproj/WebKitApple.vsprops
    +++ b/Source/WebKit/win/WebKit.vcproj/WebKitApple.vsprops
    @@ -1,12 +1,12 @@
    -<?xml version="1.0" encoding="Windows-1252"?>
    -<VisualStudioPropertySheet
    - ProjectType="Visual C++"
    - Version="8.00"
    - Name="WebKitApple"
    - >
    - <Tool
    -         Name="VCLinkerTool"
    -         AdditionalDependencies="CFNetwork$(LibraryConfigSuffix).lib CoreFoundation$(LibraryConfigSuffix).lib CoreGraphics$(LibraryConfigSuffix).lib QTMovieWin$(WebKitConfigSuffix).lib WebKitSystemInterface$(WebKitConfigSuffix).lib"
    -         DelayLoadDLLs="QTMovieWin$(WebKitConfigSuffix).dll"
    - />
    +<?xml version="1.0" encoding="Windows-1252"?>
    +<VisualStudioPropertySheet
    +       ProjectType="Visual C++"
    +       Version="8.00"
    +       Name="WebKitApple"
    +       >
    +       <Tool
    +               Name="VCLinkerTool"
    +               AdditionalDependencies="CFNetwork$(LibraryConfigSuffix).lib CoreFoundation$(LibraryConfigSuffix).lib CoreGraphics$(LibraryConfigSuffix).lib QTMovieWin$(WebKitConfigSuffix).lib WebKitSystemInterface$(WebKitConfigSuffix).lib"
    +               DelayLoadDLLs="QTMovieWin$(WebKitConfigSuffix).dll"
    +       />
     </VisualStudioPropertySheet>
    \ No newline at end of file
    diff --git a/Source/WebKit/win/WebKit.vcproj/WebKitDirectX.vsprops b/Source/WebKit/win/WebKit.vcproj/WebKitDirectX.vsprops
    index 797b4cb..c95c87d 100644
    --- a/Source/WebKit/win/WebKit.vcproj/WebKitDirectX.vsprops
    +++ b/Source/WebKit/win/WebKit.vcproj/WebKitDirectX.vsprops
    @@ -1,15 +1,15 @@
    -<?xml version="1.0" encoding="Windows-1252"?>
    -<VisualStudioPropertySheet
    - ProjectType="Visual C++"
    - Version="8.00"
    - Name="WebKitDirectX"
    - >
    -  <Tool
    -         Name="VCCLCompilerTool"
    -         AdditionalIncludeDirectories="&quot;$(DXSDK_DIR)\Include&quot;"
    - />
    -  <Tool
    -         Name="VCLinkerTool"
    -         AdditionalLibraryDirectories="$(DXSDK_DIR)\Lib\x86"
    - />
    +<?xml version="1.0" encoding="Windows-1252"?>
    +<VisualStudioPropertySheet
    +       ProjectType="Visual C++"
    +       Version="8.00"
    +       Name="WebKitDirectX"
    +       >
    +  <Tool
    +               Name="VCCLCompilerTool"
    +               AdditionalIncludeDirectories="&quot;$(DXSDK_DIR)\Include&quot;"
    +       />
    +  <Tool
    +               Name="VCLinkerTool"
    +               AdditionalLibraryDirectories="$(DXSDK_DIR)\Lib\x86"
    +       />
     </VisualStudioPropertySheet>
    \ No newline at end of file
    

  • How do I do a 'git blame' in NetBeans?
  • Undo deleted files in git?
  • Find added files in index before an initial commit is made
  • revert git rm -rf in just inititlized repo.
  • What's a `WIP` on a stash commit?
  • Finding out that a git repository has changed
  • 2 Solutions collect form web for “How can i remove 'Changes not staged for commit'? in git”

    It sounds like you are using the core.autocrlf option. What is likely happening is that the file in the repository has CRLF line endings, but due to this option being set, Git thinks that the file should have LF line endings in the repository. When you checkout the file, you are getting the file in your working directory with platform-native line endings (CRLF if on Windows, LF on Unixes, etc).

    As part of the git status operation, Git is converting those back to LF. If the file in the HEAD revision is stored in Git as having CRLF endings, that would explain why Git still sees the two versions as being different, even after you check out the revision from the index.

    The most straightforward way to detect this is to run git diff from a terminal, which will show you the CR character as ^M.

    To resolve this situation, you can just commit the files (with some message like “standardize line endings”) or you can disable core.autocrlf completely, which means that files will be stored in the repository as-is and line ending adjustment will not be performed by Git. (This may have very negative consequences if you develop with others who do not use the same platform.)

    I just want to add to @cdhowie‘s answer.

    I experienced the same issue as the OP.

    The best way to verify windows line endings is not via vim but via od:

    od -xcb foo.txt | tail
    

    Windows line endings should look like this:

    \r \n
    

    To easily get all the affected files and convert to unix (in my case) is to do this:

    git ls-files -m | xargs dos2unix
    dos2unix: converting file foo.txt to Unix format ...
    dos2unix: converting file moo.txt to Unix format ...
    
    Git Baby is a git and github fan, let's start git clone.