And without any additional tools (like 'fromdos', 'dos2unix', etc.):
git filter-branch --force --tree-filter 'git ls-files | xargs file | sed -n -e "/.*: .*text.*/s/\(.*\): .*/\1/p" | xargs -0 sed -i"" -e "s/"$(printf "\015")"$//"' --tag-name-filter cat -- --all
Crossplatform (OS X, FreeBSD, Linux) useful analog 'fromdos', 'dos2unix':
sed -i'' -e 's/'"$(printf '\015')"'$//'
Perhaps useful 'unix2dos':
sed -i '' -e 's|$|'"`printf '\015'`"'|' file.name
If are you absolytely shure what are you doing, you can use this simple inline command for delete "/r" from all files in current directory ".":
find . -type f -exec sed -i'' -e 's/'"$(printf '\015')"'$//' {} \;
Another alternative to the dos2unix command is to rely on the git itself:
git filter-branch --prune-empty --tree-filter 'git add --renormalize .' -- --all
– Vilmantas Baranauskas – 2018-12-10T06:45:46.2371Thank you, this post helped me a lot. I had a few files with spaces in their name, a little change to the original command fixed it:
git filter-branch --tree-filter 'git ls-files -z | xargs -0 dos2unix' -- --all
. Flags-z
and-0
tellgit ls-files
andxargs
to print and interpretnull
as end of line. – Ivan – 2013-11-08T14:04:49.940