20

I am using git repository. Everything is working properly except git diff command. Whenever I modify any file then git diff command showing entire file is modified even though I modified small portion of the code.

What could be the reason git diff showing entire file modified instead of small portion of the code? Also let me know setting of git diff configuration.

diff --git a/application/routes.php b/application/routes.php index 2842f8d..6629d16 100755 --- a/application/routes.php +++ b/application/routes.php @@ -1,671 +1,676 @@ -<?php -/** - * Set the routes. Each route must have a minimum of a name, a URI and a set of - * defaults for the URI. - / -?> +<?php +/* + * Set the routes. Each route must have a minimum of a name, a URI and a set of + * defaults for the URI. + */ +?> 
3
  • Can you post the output from git diff? Commented May 26, 2011 at 5:30
  • diff --git a/application/routes.php b/application/routes.php index 2842f8d..6629d16 100755 --- a/application/routes.php +++ b/application/routes.php @@ -1,671 +1,676 @@ -<?php -/** - * Set the routes. Each route must have a minimum of a name, a URI and a set of - * defaults for the URI. - / -?> +<?php +/* + * Set the routes. Each route must have a minimum of a name, a URI and a set of + * defaults for the URI. + */ +?> Commented May 26, 2011 at 5:44
  • 3
    pasting diffs into comments isn't going to work well. Perhaps you should paste it into pastebin (saved forever) and tell us the URL. Commented May 26, 2011 at 13:02

5 Answers 5

23

Compare the output of git diff and git diff -b. Whitespace may be to blame. Reflowing text might be another (you didn't mention what you were storing).

Sign up to request clarification or add additional context in comments.

2 Comments

git diff -b command showing proper diff output. Please let me know what changes i need to do. Thanks in advance
@Rahul: The trick is to figure out what whitespace is causing the trouble. There are two options: it could be line ending and it could be added/changed space tab characters. So for instance in the line that reads something like "<?php\n", you should look for spaces and tab characters before and after those text characters in what you currently have checked out, then run git stash and look for them in the previous version. git pop will recover your changes. Also, tell us operating system or systems you or anyone else who touches this code are running.
10

The file is either stored in unix mode or windows mode (with different line endings) and when you save the file you save it in the opposite format.

Comments

1

Is your editor set to automatically reformat code? Could it be the file used to use tabs for indentation and you changed it to use spaces for instance?

2 Comments

File using tabs for indentation.
@Rahul, I think your editor is modifying your file. You need to change your editor to stop doing that. One, make sure it's not reformatting code. Two, make sure it's not modifying existing line endings.
1

Try checking the files encoding. It seems that files with the same content but different encoding are marked as totally different.

Comments

1

Try running this command. It works fine for me:

git diff -U0 Filename | grep -v "diff\|index\|@@\|+++\|\---" 

This command is basically removing lines containing "diff" , "index", "---" ,"+++" , "@@" using "grep -v" command and -U0 removes extra lines displayed above and below the modified lines.

Try this for a file with one line change, you will understand it better :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.