Conventions

Read more on Stackoverflow: Why should I use core.autocrlf=true in Git? (external link)

Git Configuration

git config core.autocrlf true

 

Following the rules in your editor

You can make sure you follow this rule easily:

For visual studio, you can download this VS Settings file which will configure your environment properly.

Quick Tricks/Scripts for fixing things

Fixes "No newline at end of file" for all *.cs files (Requires Bash 4.0, based on this post http://stackoverflow.com/questions/3261925/how-to-fix-no-newline-at-end-of-file-compiler-warning-for-lots-of-files)

#!/bin/bash
shopt -s globstar
 
for i in **/*.cs ; do  echo $i; \
 if diff /dev/null "$i" | tail -1 | \
  grep '^\\ No newline' > /dev/null; then echo >> "$i"; \
 fi; done

Ensure newlines are \n (example is for *.aspx files)

#!/bin/bash
expand_func () {
  dos2unix -m -n "$1" "$1.tmp"
  mv "$1.tmp" "$1"
}
export -f expand_func
find . -name \*.aspx -exec bash -c 'expand_func {}' \;

Convert files indented with 4 spaces, to tabs

#!/bin/bash
expand_func () {
  expand -t 4 "$1" > "$1.tmp"
  mv "$1.tmp" "$1"
}
export -f expand_func
find . -name \*.aspx -exec bash -c 'expand_func {}' \;