file difference in binary files

387 views
Skip to first unread message

Christopher John

unread,
Nov 15, 2023, 8:54:06 AM11/15/23
to Repo and Gerrit Discussion
When I submitted the modification of the.c file to gerrit, gerrit displayed "file difference in binary files", which could not display the modified content normally, but I could clearly view it normally locallyDingtalk_20231115214741.jpgDingtalk_20231115214827.jpg
There are other .c files uploaded and modified on gerrit, which can be displayed normally
Dingtalk_20231115215139.jpg
Why is this happening?

Matthias Sohn

unread,
Nov 15, 2023, 9:24:17 AM11/15/23
to Christopher John, Repo and Gerrit Discussion
Does the file contain a null byte, a lone CR or a lot of non-printable characters ?
Git (and JGit) uses that as a heuristic to detect if a file has binary content. 
Try to configure .gitattributes to consider .c files as text by adding this to .gitattributes in the root of your repo:
*.c		text
-Matthias

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/0bdc8d6b-5d98-4450-a318-f8e20cdcc700n%40googlegroups.com.

Sven Selberg

unread,
Nov 15, 2023, 9:26:50 AM11/15/23
to Repo and Gerrit Discussion
My best bet would be that these files were created on a Windows system.
The presence of Carriage Return and Line Feed control characters makes the file be interpreted as binary.
https://issues.gerritcodereview.com/issues/40014911

You can also check the encoding of the file, I believe git still considers utf-16 and utf-8 (with bom) as binary by default.
Ensure that it's plain utf-8 if it's something else.
 

Christopher John

unread,
Nov 16, 2023, 8:18:52 AM11/16/23
to Repo and Gerrit Discussion
I tried to increase the .gitattributes configuration in the git repository on the gerrit server and then restart gerrit, but the problem still did not solve

Christopher John

unread,
Nov 16, 2023, 8:22:10 AM11/16/23
to Repo and Gerrit Discussion
I converted the encoding of the file in the local git library, converted the file encoding to utf-8, and submitted it again, but the problem still occurred.
For the "^M" character mentioned in the article, I used dos2unix to convert it in Ubuntu and then submitted it, but it still couldn't solve the problem.

Sven Selberg

unread,
Nov 16, 2023, 8:54:22 AM11/16/23
to Repo and Gerrit Discussion
On Thursday, November 16, 2023 at 2:22:10 PM UTC+1 Christopher John wrote:
I converted the encoding of the file in the local git library, converted the file encoding to utf-8, and submitted it again, but the problem still occurred.
For the "^M" character mentioned in the article, I used dos2unix to convert it in Ubuntu and then submitted it, but it still couldn't solve the problem.

I don't have any further suggestions since these actions should have fixed it. Difficult to troubleshoot without access to the actual file.

Since you seems to have access to an Ubuntu machine, does Ubuntu consider it to be a binary file?
$ file --mime $PATH_TO_C_FILE
What does your .gitatributes file look like and were is it added?

Christopher John

unread,
Nov 17, 2023, 3:15:48 AM11/17/23
to Repo and Gerrit Discussion
Thank you very much for your help, the problem has been solved, the problem is indeed caused by coding anomalies, I transcode and push once again locally, after the modification is push once, the modification can be displayed normally when the second submission
Reply all
Reply to author
Forward
0 new messages