Line endings messed up in Git - how to track changes from another branch after a huge line ending fix?

后端 未结 5 887
遇见更好的自我
遇见更好的自我 2020-12-02 08:02

We are working with a 3rd party PHP engine that gets regular updates. The releases are kept on a separate branch in git, and our fork is the master branch.

This way

5条回答
  •  伪装坚强ぢ
    2020-12-02 08:34

    I finally managed to solve it.

    The answer is:

    git filter-branch --tree-filter '~/Scripts/fix-line-endings.sh' -- --all
    

    fix-line-endings.sh contains:

    #!/bin/sh
    find . -type f -a \( -name '*.tpl' -o -name '*.php' -o -name '*.js' -o -name '*.css' -o -name '*.sh' -o -name '*.txt' -iname '*.html' \) | xargs fromdos
    

    After all line endings were fixed in all trees in all commits, I did an interactive rebase and removed all commits that were fixing line endings.

    Now my repo is clean and fresh, ready to be pushed :)

    Note to visitors: do not do this if your repo has been pushed / cloned because it will mess things up badly!

提交回复
热议问题