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

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!

Leave a Comment