Git mark file as binary to avoid line separator conversion

后端 未结 3 1958
半阙折子戏
半阙折子戏 2021-01-04 11:35

I have a text file with sample data which I want to put under Git control (on Windows). How can I tell Git to treat this file as binary, so it does not convert line separato

相关标签:
3条回答
  • 2021-01-04 12:15

    Write this in .gitattributes (in the file’s directory or higher up):

    myfile.bin -text
    

    See the manual for more explanation.

    0 讨论(0)
  • 2021-01-04 12:16

    Marking files as binary

    Git usually guesses correctly whether a blob contains text or binary data by examining the beginning of the contents. However, sometimes you may want to override its decision, either because a blob contains binary data later in the file, or because the content, while technically composed of text characters, is opaque to a human reader. For example, many postscript files contain only ascii characters, but produce noisy and meaningless diffs.

    The simplest way to mark a file as binary is to unset the diff attribute in the .gitattributes file:

    *.ps -diff

    This will cause git to generate Binary files differ (or a binary patch, if binary patches are enabled) instead of a regular diff.

    In summary: specify -diff in .gitattributes.

    0 讨论(0)
  • 2021-01-04 12:20

    While -text in .gitattributes did not worked,

    myfile.bin binary
    

    did.

    0 讨论(0)
提交回复
热议问题