git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: change the filetype from binary to text after the file is commited to a git repo

From
Jeff King <peff@peff.net>
Date
Jul 24, 2017, 18:18 UTC
Message-ID
<20170724181835.zo3lcv7pxmkif2jr@sigill.intra.peff.net>
In-Reply-To
<CAEor4NHDNL4CQP_FpCuJ_3F86-A3P8i=yvp1AZr-NKt0i1=cXw@mail.gmail.com>
On Mon, Jul 24, 2017 at 07:11:06AM +0200, tonka tonka wrote:
Show 8 quoted lines
> I have a problem with an already committed file into my repo. This git
> repo was converted from svn to git some years ago. Last week I have
> change some lines in a file and I saw in the diff that it is marked as
> binary (it's a simple .cpp file). I think on the first commit it was
> detected as an utf-16 file (on windows). But no matter what I do I
> can't get it back to a "normal text" text file (git does not detect
> that), but I is now only utf-8. I also replace the whole content of
> the file with just 'a' and git say it's binary.

Git doesn't store a flag for "binary-ness" on each file (though see below). As the diffs are generated on the fly when you ask to compare two versions, so too is the determination of "is this binary".

The default heuristic looks at file size (by default, if the file is over 500MB it's considered binary) and whether it has any zero-byte characters in the first few kilobytes. But note that if _either_ side of a diff is considered binary, then Git won't show a text diff.

If you want a particular diff to show all content, even if it doesn't look like text, add "-a" to your git invocation (e.g., "git show -a").

That said, you can also use .gitattributes (see "git help attributes") to mark a file as binary or not-binary, skipping the heuristic check. I'm guessing since you converted from svn that you don't have a .gitattributes file, but it's possible that somebody later added one that marks the file as binary (and so the solution would be to drop that entry).

-Peff
Previous: tonka tonkaNext: tonka3100@gmail.com
Message 2 of 6 in “change the filetype from binary to text after the file is commited to a git repo”
  1. tonka tonkaJul 24, 2017
  2. Jeff KingJul 24, 2017
  3. tonka3100@gmail.comJul 24, 2017
  4. Jeff KingJul 24, 2017
  5. Jeff KingJul 24, 2017
  6. tonka3100@gmail.comJul 24, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.