What is the difference between diff and diff=astextplain?
Asked Answered
F

2

18

Can someone help me. I am using Git (GitHub) and trying to decide what to set my *.sql files to in the gitattributes. I've seen people use

*.sql diff=astextplain
*.sql diff
*.sql text=auto

I was advised to set this to the second option, but I am just wondering what is the difference between that and the other two.

Fustanella answered 26/1, 2015 at 7:42 Comment(0)
E
30

TL;DR

  • diff=astextplain (msysGit only): converts those files (under the condition that their extension be *.doc, *.pdf, *.rtf, etc.) to a text format before generating their diff.
  • diff: treat those files as plain text for generating their diff.
  • text=auto: automatically normalize EOL characters (to LF) in files deemed to be text files by Git.

More details

diff=astextplain

The string value astextplain is not part of Git core: in fact, running

git grep "astextplain"

in the Git project repository returns nothing. As far as I can tell, it's a shell script that ships with msysGit and allows you to convert files such as

  • Word documents,
  • PDF,
  • RTF

to a text format before generating their diff.

diff

According to the gitattributes man page:

The attribute diff affects how Git generates diffs for particular files. [...]

A path to which the diff attribute is set is treated as text, even when they contain byte values that normally never appear in text files, such as NUL.

text=auto

According to the gitattributes man page:

When text is set to "auto", the path is marked for automatic end-of-line normalization. If Git decides that the content is text, its line endings are normalized to LF on checkin.

Egarton answered 26/1, 2015 at 10:31 Comment(2)
This answer might need an update. msysGit has been superseded by Git for Windows 2.x.Tripitaka
Yes, the answer is more than 7 years old. I'm not familiar with Git for Windows 2.x. If you know what needs to be modified in my answer, feel free to edit it. Or post your own answer.Egarton
T
2

The accepted answer is outdated. msysGit has been superseded by Git for Windows 2.x.

astextplain is a script available in Git for Windows' git-extra package and can be read online.

From the Git For Windows Wiki,

The git-extra package modifies the MSYS2 environment heavily (sometimes in ways that are tedious to undo). The package can be skipped if you want to keep your MSYS2 pristine. As of this writing, the package:

  • installs various other helpers: blocked-file-util, create-shortcut, git-askyesno, git-credential-helper-selector, proxy-lookup, WhoUses, astextplain, notepad, vi, wordpad
Tripitaka answered 20/12, 2022 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.