Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:08:19+00:00 2026-06-15T08:08:19+00:00

I recently added a .gitattributes file to a c# repository with the following settings:

  • 0

I recently added a .gitattributes file to a c# repository with the following settings:

*            text=auto
*.cs         text diff=csharp

I renormalized the repository following these instructions from github and it seemed to work OK.

The problem I have is when I checkout some files (not all of them) I see lots of weird characters mixed in with the actual code. It seems to happen when git runs the files through the lf->crlf conversion specified by the .gitattributes file above.

According to Notepad++ the files that get messed up are using UCS-2 Little Endian or UCS-2 Big Endian encoding. The files that seem to work OK are either ANSI or UTF-8 encoded.

For reference my git version is 1.8.0.msysgit.0 and my OS is Windows 8.

Any ideas how I can fix this? Would changing the encoding of the files be enough?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:08:20+00:00Added an answer on June 15, 2026 at 8:08 am

    This happens if you use an encoding where every character is two bytes.
    CRLF would then be encoded as \0\r\0\n.

    Git thinks it’s a single-byte encoding, so it turns that into \0\r\0\r\n.
    This makes the next line one byte off, causing every other line be full of Chinese. (because the \0 becomes the low-order byte rather than the high-order byte)

    You can convert files to UTF8 using this LINQPad script:

    const string path = @"C:\...";
    foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
    {
        if (!new [] { ".html", ".js"}.Contains(Path.GetExtension(file)))
            continue;
        File.WriteAllText(file, String.Join("\r\n", File.ReadAllLines(file)), new UTF8Encoding(encoderShouldEmitUTF8Identifier: true));
        file.Dump();
    }
    

    This will not fix broken files; you can fix the files by replacing \r\n with \n in a hex editor. I don’t have a LINQPad script for that. (since there’s no simple Replace() method for byte[]s)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently added these lines to my ~/.bashrc file to show the current branch
I recently added filelocks to my downloader asynctask: FileOutputStream file = new FileOutputStream(_outFile); file.getChannel().lock();
I recently added some namespaces to my web.config file so that all of my
I've recently added this little bit of code to my .htaccess file: RewriteCond %{REQUEST_FILENAME}
I recently added a new table to my database and am getting the following
I recently added the line (set-default-font -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1) to my .emacs file. After that find-file-other-window
I recently added a favicon to a Django site by editing my httpd.conf file:
I recently added the file Serial.c and Serial.h to my Xcode project. The code
I recently added the following bash function definition to my /etc/profile in Ubuntu 11.04
I recently added a 16px by 16 px favicon.ico file to my htdocs directory.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.