Search code examples
gitgit-filter-branch

git filter branch to git filter repo conversion


I am following this command to perform prettier over all commits in my git repository:

git filter-branch --tree-filter 'prettier --write "**/**.js" || echo “Error formatting, possibly invalid JS“' -- --all

I want to perform the same in git filter repo but I am not even sure whether that is achievable. Can anyone help on how to approach this with git filter repo?


Solution

  • I want to perform the same in git filter repo but I am not even sure whether that is achievable

    Yes, it is a blob callback and allows you to call any script/command you want on said blob, similar to what is done in newren/git-filter-repo issue 45, and this example

    git filter-repo --force --blob-callback '
      import black
      blob.data = black.reformat_commit(blob.data.decode(), mode=black.FileMode()).encode()
    '
    

    With reformat_commit as in this python script.