Neither git command does modify any characters in its output apart from adding control characters to enable color output and external text conversion filters for binary files if specifically enabled. However, the output is usually piped through a pager application. On many Linux systems the default pager is less
and that does do replace tabs! You can easily test this behavior by piping the diff output into a file or through another application, e.g. git diff | cat
will not tinker with tabs and should make them visible if paging is the culprit.
However, some terminal emulators might also do this and piping through cat
would still "show" spaces instead of tabs. This can be verified by piping through something like hexdump: git diff | hd
where you should see 0x09 aka \t
characters where tabs are in the actual source code.
You can disable paging temporarily by using git --no-pager [command]
or by simply piping the output through cat
. There are also different configuration options to influence the use of pagers more permanently, e.g., disabling it globally for specific commands, e.g., for diff: git config --global pager.diff false