Set file as non-binary in git

后端 未结 2 1394
独厮守ぢ
独厮守ぢ 2021-01-02 08:53

I have a folder with lots of .cs files. Some of these files (for some reason) are tracked as binary and the git diff command doesn\'t work normally with them. I

相关标签:
2条回答
  • 2021-01-02 09:08

    You can do this to force git to think it's text:

     *.cs diff
    

    You'll want to make sure it actually is text though. Forcing Git to think your file is text when it actually isn't can cause extremely bad behavior in a variety of situations.

    You may need to set a couple of other attributes too:

     *.cs diff merge text
    

    The text is useful for EOL normalization. You might need merge if Git still thinks the files are binary at merge time.

    However, the real question is "Why is Git marking my file as binary?" The answer is because it's seeing a NUL (0) byte somewhere within the first 8000 characters of the file. Typically, that happens because the file is being saved as something other than UTF-8. So, it's likely being saved as UCS-2, UCS-4, UTF-16, or UTF-32. All of those have embedded NUL characters when using ASCII characters. So, while your question says you did re-saved the files as UTF-8, you may want to check again with a hex editor. I suspect that they are not UTF-8, and that's the core of the problem.

    0 讨论(0)
  • 2021-01-02 09:18

    In Sourcetree version 3.1.2:

    • Tools > Options > Diff
    • Add an extra zero to 'Size Limit (Text)'
    • Add an extra zero to 'Size Limit (Binary)'
    • Click OK
    • View > Refresh (or F5)
    0 讨论(0)
提交回复
热议问题