0

I've updated a four lines of code in a file, verified everything is working, and went to commit my code.

I check the git status and see that git recognizes that I've changed the file I've been working on.

However, when I do a git diff, it says I've changed a different line of code, and that the lines I did change were not changed.

How can I get fix this and get git to recognize my changes correctly?

My code in question (changed lines marked in comments):

<cfcomponent displayname="Config" output="false" alias="com.ams.sms.timekeeper.ConfigBean">
 <cfproperty name="Config_ID" type="numeric" default="" />
 <cfproperty name="School_ID" type="numeric" default="" />
 <cfproperty name="Is_Recycled" type="numeric" default="" />
 <cfproperty name="Period_Type" type="numeric" default="" />
 <cfproperty name="Rounding_Unit" type="numeric" default="" />
 <cfproperty name="Grace_Time" type="numeric" default="" />
 <cfproperty name="Auto_Create_Periods" type="boolean" default="" />
 <cfproperty name="Verification_Method" type="numeric" default="" />
 <cfproperty name="Allow_Manual" type="boolean" default="" />
 <!---
 PROPERTIES
 --->
 <cfscript>
 variables.Config_ID="";
 variables.School_ID="";
 variables.Is_Recycled=0; // changed
 variables.Period_Type=1;
 variables.Rounding_Unit=0; //changed
 variables.Grace_Time=0; //changed
 variables.Auto_Create_Periods=true;
 variables.Verification_Method=0; //changed
 variables.Allow_Manual=true;
 </cfscript>

git diff returns the following, saying that I've updated the line 1, which I haven't, and ignores the changes on the lines further in:

$ git diff
diff --git a/ams/sms/timekeeper/ConfigBean.cfc b/ams/sms/timekeeper/ConfigBean.cfc
index e2db893..9dabfc9 100644
--- a/ams/sms/timekeeper/ConfigBean.cfc
+++ b/ams/sms/timekeeper/ConfigBean.cfc
@@ -1 +1 @@
-<cfcomponent displayname="Config" output="false" alias="com.ams.sms.timekeeper.ConfigBean">^M^M
\ No newline at end of file
+<cfcomponent displayname="Config" output="false" alias="com.ams.sms.timekeeper.ConfigBean">^M^M
\ No newline at end of file
(END)
asked May 9, 2016 at 17:39
2
  • Have you already called git add on the file? Commented May 9, 2016 at 17:43
  • This is before an add, but I get the same results doing a diff after doing the add as well. Commented May 9, 2016 at 17:52

1 Answer 1

1

I'd say your line separators are a bit bogus.
Do you have old mac line endings in the file (only \r)?
Because the diff sees the whole file as one line (you see that as after your first line it says "No newline at end of file" which means that after that line the file is finished already) and vim just doesn't display the rest of the line or something like that.

answered May 9, 2016 at 17:44
Sign up to request clarification or add additional context in comments.

6 Comments

It's possible, as it's an old file, but most of the files originated on Windows.
Diff normally handles linux (\n) and windows (\r\n) endings well, while with windows line endings it may show the \r as ^M like in your output. That's why I suppose this. Use git difftool with a tool that can handle it like P4Merge (the best free diff- and mergetool I know) or maybe try adding -w to the diff command for ignoring whitespaces, but I don't think the latter will help you in this situation.
I installed p4Merge, and doing the visual merge here, it shows the correct changes. Sourcetree, however, still shows the wrong one.
As I said, check the line endings in some editor like jEdit or some hex editor that displays which line endings the file is using. I still bet there are only \rs as line endings in there.
That did it. It had ^M line endings.
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.