Git diff command showing entire file is modified instead of showing modified small part of code

前端 未结 5 946
旧巷少年郎
旧巷少年郎 2021-02-07 02:02

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

相关标签:
5条回答
  • 2021-02-07 02:45

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

    0 讨论(0)
  • 2021-02-07 02:49

    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.

    0 讨论(0)
  • 2021-02-07 02:51

    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?

    0 讨论(0)
  • 2021-02-07 02:54

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

    0 讨论(0)
  • 2021-02-07 02:57

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

    0 讨论(0)
提交回复
热议问题