Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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:

% 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
like image 928
michael Avatar asked Jan 03 '13 23:01

michael


1 Answers

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.)

like image 188
cdhowie Avatar answered Sep 21 '22 05:09

cdhowie