Skip to content

Instantly share code, notes, and snippets.

@erik4github
Created August 24, 2022 03:57
Show Gist options
  • Save erik4github/dde6f27d987120597cafbfd0d54d271d to your computer and use it in GitHub Desktop.
Save erik4github/dde6f27d987120597cafbfd0d54d271d to your computer and use it in GitHub Desktop.
Normalize Git line endings

often I get annoying CRLF to LF issues when using an editor that doesn't let you specify default line endings like Obsidian, which is super annoying when syncing notes across devices

so here's a script to use. if you want to filter (e.g. only markdown files) you can pass it as an arg like normalize *[.md]

#usr/bin/bash
set -u
if [[ -z $1 ]];
then
git ls-files -z | xargs -0 dos2unix
else
git ls-files -z "$1" | xargs -0 dos2unix
fi
# normalize entire directory so git stops saying there are changes
git add --renormalize .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment