Search code examples
gitgithubgit-lfs

What does %f represent in the git clean/smudge filters


Inside my ~/.gitconfig file I see that there is the following lfs filter:

[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true

Question: What does %f represent in the lfs filter? My understanding is it represents the file path but I'm not sure what file path it represents.


Solution

  • In the .gitattributes "filter" section, it is presented as:

    Sequence "%f" on the filter command line is replaced with the name of the file the filter is working on.
    A filter might use this in keyword substitution. For example:

    [filter "p4"]
      clean = git-p4-filter --clean %f
      smudge = git-p4-filter --smudge %f
    

    Note that "%f" is the name of the path that is being worked on.
    Depending on the version that is being filtered, the corresponding file on disk may not exist, or may have different contents.

    So, smudge and clean commands should not try to access the file on disk, but only act as filters on the content provided to them on standard input.