Git clean and smudge filters don't do anything

后端 未结 1 947
旧巷少年郎
旧巷少年郎 2021-02-19 00:46

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

相关标签:
1条回答
  • 2021-02-19 01:07

    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:

    1. Specify git --version and the operating system;
    2. Publish and link entire or partial project directory (including .git) if possible, or try to reproduce the failure with filter on some simple test repository (which can be published).
    3. Try to set up (or inspect the setup) and use filters completely from console and include the entire output in the question.

    After ensuring the clean filter works for one file, you can continue with the other file and smudge filters.

    0 讨论(0)
提交回复
热议问题