I'm trying to get a git smudge filter to work in ubuntu, as described in this stackoverflow answer: https://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs

The goal is to convert spaces to tabs on checkout.

In my .gitconfig I have this entry:

[filter "tabspace"]
    smudge = unexpand --tabs=4 --first-only
    clean = expand --tabs=4 --initial

As an example, consider the lxqt-panel repository which uses spaces for indentation: https://github.com/lxde/lxqt-panel

In lxqt-panel/.git/info/attributes, I enabled the tabspace filter:

*.cpp   filter=tabspace
*.h     filter=tabspace

According to the Stackoverflow Answer various online sources, running git checkout HEAD -- ** should now convert all spaces to tabs. However, in my case git seems to ignore these settings completely; running unexpand manually works though.

What am I missing here?

I'm using git 2.11.0 on Ubuntu 16.04.

1 Answer 1


git checkout HEAD -- ** will only convert files that have changes. Unchanged files will not be touched, that's why nothing is replaced in them. To force updating all files, you could remove them and then reset. But make sure you don't have any uncommitted changes, because they will be lost. For example you could do this:

git rm -r .
git reset --hard

Or, if you prefer, you could replace only all .h and .cpp files with:

rm **/*.{h,cpp}
git checkout .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .