36

The standard spacing for a tab is 8 characters.

I prefer to view that as 4 characters in my editors and console. I can easily change this default behavior on console with the tabs command:

tabs -4

However, when using git diff or git show it displays in the default 8 character tab whitespace.

How can I get git diff to render tabs as 4 character spaces?

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167

1 Answers1

54

This actually has nothing to do with git diff.

git diff actually renders a tab, which is later converted by your terminal emulators (for instance, gnome-terminal) to spaces.

Go to the preference of your terminal emulator to change that setting.


Also, git may use a pager, so you might want to configure it like that:

git config --global core.pager 'less -x1,5'

More information here: setting tabwidth to 4 in git show / git diff

Community
  • 1
  • 1
blue112
  • 52,634
  • 3
  • 45
  • 54
  • 6
    Hmm, my terminal is set to 4... This just doesn't appear the same in `git diff` So if I `cat file` then tabs are 4 chars, but `git diff file` they are instead 8. – Jeff Puckett Sep 06 '16 at 15:25
  • 5
    Nice, I see your edit. It is the pager, thanks! Will accept in 6 more minutes... – Jeff Puckett Sep 06 '16 at 15:29
  • 7
    For eventual use, `export LESS=Rx4` can be useful instead of changing the global Git configuration. – Ferenc Wágner Aug 02 '18 at 11:22
  • How can it be converted by the terminal emulator and yet changing of the behaviour is done in... `less`? If `less` output a tab, which is then converted by the terminal emulator, then there would be no need to change settings for `less` specifically? – Armen Michaeli Feb 24 '22 at 10:15