I defined smudge and clean filters for my git repository. I tested the scripts individually and I\'m pretty sure they work correctly.
But when I git commit &&a
From the visible information I can only assume that the problem is in trying to configure clean and smudge filters in the wrong place.
I see the lines in .gitconfig
file, but unless it is also a home directory, it is not the same as .git/config
, where Git looks for them.
Try executing this command to see if Git sees the filter:
$ git config filter.zshrc.clean
zsh zshrc-clean.zsh
If you see nothing instead, the filter is not actually configured. You can use git config filter.zshrc.clean "zsh zshrc-clean.zsh"
instead of editing config file manually.
Unfortunately, if a filter mentioned in .gitattributes
is missing from actual git config, it is silently ignored.
Here is a direct way to inspect if the filter is being called while adding new or changed file (remove and re-add if it is already in index); Linux-only:
$ strace -qqqqqqq -fe execve -e signal=none git add zsh/zshrc
execve("/home/vi/bin/git", ["git", "add", "zsh/zshrc"], [/* 29 vars */]) = 0
[pid 7061] execve("/bin/sh", ["/bin/sh", "-c", "zsh zshrc-clean.zsh", "zsh zshrc-clean.zsh"], [/* 31 vars */]) = 0
[pid 7062] execve("/usr/bin/zsh", ["zsh", "zshrc-clean.zsh"], [/* 31 vars */]) = 0
[pid 7063] execve("/bin/sed", ["sed", "/export HOMEBREW_GITHUB_API_TOKE"..., "/dev/stdin"], [/* 31 vars */]) = 0
One can inspect the resulting blob after the adding:
$ git ls-files -s
100644 4138315597d69f0da1deae1b6eff0c30dc447e9c 0 zsh/zshrc
$ git cat-file blob 4138315597d69f0da1deae1b6eff0c30dc447e9c
export HOMEBREW_GITHUB_API_TOKEN =REPLACEME:zsh:HOMEBREW_GITHUB_API_TOKEN
If the suspected problem is actually in .gitattributes
, you can check if the attribute is actually applied to the file:
$ git check-attr -a zsh/zshrc
zsh/zshrc: filter: zshrc
To get further help, you can:
git --version
and the operating system;.git
) if possible, or try to reproduce the failure with filter on some simple test repository (which can be published).After ensuring the clean filter works for one file, you can continue with the other file and smudge filters.