Must-Knows for Sitecore Project Git Repos

Or, How To Avoid And Fix Content-Length / Line Ending / CR LF / Corrupt File Issues

Thinking of firing up a git repo to store your some or all of your Sitecore project files? There’s a few things you’ll want to be aware of first. Proper setup from the beginning will save you a lot of time.

Note: If you have a fancy up to date development environment, you may not even need to worry about these details as these issues have been resolved in later versions of TDS. But, if you’re reading this post, it probably already means you screwed up.

First, you want to make sure that git is configured properly in terms of the line endings it applies on checkin and checkout. This helpful article explains almost everything you need to know:

https://help.github.com/articles/dealing-with-line-endings/

A major takeaway from the github guide is that it’s probably best if you have a property configured .gitattributes file in the root of your project directory right from the very beginning.

Your .gitattributes file should contain some or all of the following; particularly the last line:


# Source: https://github.com/HedgehogDevelopment/tds-codegen/blob/master/.gitattributes

# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp
*.sln    merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc    diff=astextplain
*.DOC    diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF    diff=astextplain
*.rtf    diff=astextplain
*.RTF    diff=astextplain

# Custom for TDS/Sitecore serialization (*IMPORTANT*)
*.item -text

Doing so will ensure that when .item files are pulled into the repo, they won’t get zapped.

A few last protips:

  • Don't ignore git messages saying “CRLF will be replaced by LF” or vice versa. It’s not always a problem, but it can be for certain types of files.
  • When in doubt about file differences, compare files using Notepad ++ or your favourite diff tool and compare the white spaces. CR and LF symbols will be visually discernible that way.
  • If you royally pooched your repo but managed to recover, be sure to check all of your different committed file types to ensure that they are still valid and that they can be read by their intended applications. For example, font files can be corrupted by line ending changes.

Good luck out there.

Fish