1

I am facing a strange issue with git diff. The output of the command shows the files that were changed but does not show the exact change in the lines. It happens for both commands:

git diff 

and

git diff --staged

enter image description here

Could anyone please suggest why this could be happening? Thanks!

I tried searching online but apparently, this is not a common issue and --name-only is the option to display only file names. In my case, the default output shows only modified file names.

Ninja
  • 57
  • 1
  • 11
  • seeing `git diff` turn into `diff -git` gives me a hint that perhaps your `git` command is aliased on your machine? What OS are you running (Windows??)? What happens when you type in `which git` or `gcm git`? – Michael Dautermann Dec 25 '22 at 11:37
  • yes, I am using Windows. gcm git returns the below: CommandType: Application Name: git.exe Version: 2.39.0.2 Source: C:\Program Files\Git\cmd\git.exe – Ninja Dec 25 '22 at 11:40
  • 1
    The reason is given in the output: **`Binary`** (!) `files differ`. See `man git diff` for options to print the difference between binary files too, e.g. `-a`/`--text` or `--binary` or `--textconv`. – Socowi Dec 25 '22 at 11:48
  • @MichaelDautermann The "`diff --git ...`" is part of git diff's usual output and does not indicate any problems. If `git` was aliased, debugging with `which` would only cause confusion, as `which` cannot detect aliases. Forget about `which` and always use `command -v` instead. `command` is reliable and also more portable. – Socowi Dec 25 '22 at 12:05
  • Thanks all for pointing me to the right direction. I then checked why the git treated these txt files as binary. Looks like if I create them using `echo "sample text" > filename.txt` in Powershell, this are treated as binary. This is due to the default behavior of `>` that causes UTF-16LE encoding. However, if I created a new file from file explorer, git diff works as expected. Similar issue mentioned here: https://stackoverflow.com/questions/6855712/why-does-git-treat-this-text-file-as-a-binary-file. – Ninja Dec 25 '22 at 13:39

0 Answers0