Conventions
- Unless absolutely necessary, binary files should not be checked into the Git repository
- Text files should be encoded with UTF-8
- Line endings should be set to \n, and every text file should end with a newline character
- Lines should be free of trailing spaces
- Lines are indented with tab characters (\t)
- not 4 spaces (as is Visual Studio's default)
- not 8 spaces, etc.
Read more on Stackoverflow: Why should I use core.autocrlf=true in Git? (external link)
Git Configuration
Code Block |
---|
git config core.autocrlf true |
Following the rules in your editor
You can make sure you follow this rule easily:
- For Vim users, you're all set out of the box! Just don't change your
eol
setting. - For TextMate users, you can install the Avian Missing Bundle and add
TM_STRIP_WHITESPACE_ON_SAVE = true
to your.tm_properties
file. - For Sublime users, set the
ensure_newline_at_eof_on_save
option totrue
. - For RubyMine, set "Ensure line feed at file end on Save" under "Editor."
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)
Code Block | ||
---|---|---|
| ||
#!/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)
Code Block | ||
---|---|---|
| ||
#!/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
Code Block | ||
---|---|---|
| ||
#!/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 {}' \; |