{"thread":{"id":"55363","subject":"git diff --text does not work during rebase for binary files","startedAt":"2021-03-21T17:41:32Z","lastAt":"2021-03-26T11:32:09Z","messageCount":4,"participants":["Дилян Палаузов","Bagas Sanjaya","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"419877","messageId":"6afc8f1365627f08247f73da7e7e362c0b8ea560.camel@aegee.org","threadId":"55363","inReplyTo":null,"subject":"git diff --text does not work during rebase for binary files","fromName":"Дилян Палаузов","fromEmail":"dilyan.palauzov@aegee.org","sentAt":"2021-03-21T17:30:57Z","receivedAt":"2021-03-21T17:41:32Z","isPatch":false,"sender":{"key":"dilyan.palauzov@aegee.org","avatar":null},"body":"Hello,\n\nI create a small text file ending with \\0 and add it to git:\n\nIn .gitattributes I specify:\n\n*.txt diff merge=text text\n\nI create several commits by changing the small text file.\n\nThe result is at https://github.com/dilyanpalauzov/git-diff-biinary .\n\nI do now\n\n  git rebase -i HEAD~2\nand before the “second commit” type E to edit that commit.\n\nI change the small file.\n\ngit add a.txt && git rebase --continue\n\ngit says:\n\n[detached HEAD bc00e34] second commit\n Date: Sun Mar 21 19:16:15 2021 +0200\n 1 file changed, 2 insertions(+), 1 deletion(-)\nwarning: Cannot merge binary files: a.txt (HEAD vs. 04c77de (third\ncommit))\nAuto-merging a.txt\nCONFLICT (content): Merge conflict in a.txt\nerror: could not apply 04c77de... third commit\nResolve all conflicts manually, mark them as resolved with\n\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\nYou can instead skip this commit: run \"git rebase --skip\".\nTo abort and get back to the state before \"git rebase\", run \"git rebase\n--abort\".\nCould not apply 04c77de... third commit\n\n\n'git diff' and 'git diff --text' show:\n\ndiff --cc a.txt\nindex 7a61015,dc817ec..0000000\n--- a/a.txt\n+++ b/a.txt\n\nThe file does not contain <<HEAD===>>> markers, despite having\nmerge=text attribute.\n\nHOW CAN I force git diff to show the differences and git merge to\ninclude the <<<===>>> markers?\n\nI have to say, that at different occassions git diff --text does work\nass expected (e.g. when I call git diff --cached --text).\n\nI call now \ngit rebase --abort\ngit log -p\n\ngit shows the differences in the small text file ending with \\0.  So\napparently log reads the option, but diff does not.\n\nUsing git 2.30.2.\n\nGreetings\n  Дилян\n\n"},{"id":"419907","messageId":"4ef94ca7-ec69-f350-1d76-6bb8745786f1@gmail.com","threadId":"55363","inReplyTo":"6afc8f1365627f08247f73da7e7e362c0b8ea560.camel@aegee.org","subject":"Re: git diff --text does not work during rebase for binary files","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2021-03-22T05:53:19Z","receivedAt":"2021-03-22T05:54:23Z","isPatch":false,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"\n\nOn 22/03/21 00.30, Дилян Палаузов wrote:\n> Hello,\n> \n> I create a small text file ending with \\0 and add it to git:\n\nDid you mean `echo -e \"\\0\" >> a.txt`?\n\n> In .gitattributes I specify:\n> \n> *.txt diff merge=text text\n> \n> I create several commits by changing the small text file.\n> \n> The result is at https://github.com/dilyanpalauzov/git-diff-biinary .\n> \n> I do now\n> \n>    git rebase -i HEAD~2\n> and before the “second commit” type E to edit that commit.\n> \n> I change the small file.\n> \n> git add a.txt && git rebase --continue\n> \n> git says:\n> \n> [detached HEAD bc00e34] second commit\n>   Date: Sun Mar 21 19:16:15 2021 +0200\n>   1 file changed, 2 insertions(+), 1 deletion(-)\n> warning: Cannot merge binary files: a.txt (HEAD vs. 04c77de (third\n> commit))\n> Auto-merging a.txt\n> CONFLICT (content): Merge conflict in a.txt\n> error: could not apply 04c77de... third commit\n> Resolve all conflicts manually, mark them as resolved with\n> \"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n> You can instead skip this commit: run \"git rebase --skip\".\n> To abort and get back to the state before \"git rebase\", run \"git rebase\n> --abort\".\n> Could not apply 04c77de... third commit\n> \n> \n> 'git diff' and 'git diff --text' show:\n> \n> diff --cc a.txt\n> index 7a61015,dc817ec..0000000\n> --- a/a.txt\n> +++ b/a.txt\n> \n> The file does not contain <<HEAD===>>> markers, despite having\n> merge=text attribute.\n> \n> HOW CAN I force git diff to show the differences and git merge to\n> include the <<<===>>> markers?\n> \n> I have to say, that at different occassions git diff --text does work\n> ass expected (e.g. when I call git diff --cached --text).\n> \n> I call now\n> git rebase --abort\n> git log -p\n> \n> git shows the differences in the small text file ending with \\0.  So\n> apparently log reads the option, but diff does not.\n> \n> Using git 2.30.2.\n> \n> Greetings\n>    Дилян\n> \n\nDoes `file a.txt` shows it as being binary file? I do the similar and it just says \"data\".\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"},{"id":"419913","messageId":"3807b29f442ab7026418511f058ff9513ee200ec.camel@aegee.org","threadId":"55363","inReplyTo":"4ef94ca7-ec69-f350-1d76-6bb8745786f1@gmail.com","subject":"Re: git diff --text does not work during rebase for binary files","fromName":"Дилян Палаузов","fromEmail":"dilyan.palauzov@aegee.org","sentAt":"2021-03-22T08:45:39Z","receivedAt":"2021-03-22T08:46:46Z","isPatch":false,"sender":{"key":"dilyan.palauzov@aegee.org","avatar":null},"body":"Hello,\n\nI mean:\n\ngit init\necho -e \"AB RA\\nCADABRA\\0\" > a.txt && git add a.txt && git commit -\nm\"Initial\"\necho -e \"AB2RA\\nCADABRA\\0\" > a.txt && git add a.txt && git commit -\nm\"Second\"\necho -e \"AB3RA\\nCADABRA\\0\" > a.txt && git add a.txt && git commit -\nm\"Third\"\n\ngit log -pa   show the diffs and handles the file as text.\n\ngit rebase -i HEAD~2\n\nI EDIT the “Second” commit (the one before “Third”, not the second in\nthe editor).\n\n\nmaster|REBASE 1/2$ echo -e \"AB4RA\\nCADABRA\\0\" > a.txt && git add a.txt\n&& git rebase --continue\t\n\n[detached HEAD 78408d2] Second\n Date: Mon Mar 22 10:35:57 2021 +0200\n 1 file changed, 0 insertions(+), 0 deletions(-)\nwarning: Cannot merge binary files: a.txt (HEAD vs. 149b67e (Third))\nAuto-merging a.txt\nCONFLICT (content): Merge conflict in a.txt\nerror: could not apply 149b67e... Third\nResolve all conflicts manually, mark them as resolved with\n\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\nYou can instead skip this commit: run \"git rebase --skip\".\nTo abort and get back to the state before \"git rebase\", run \"git rebase\n--abort\".\nCould not apply 149b67e... Third\nmaster|REBASE 2/2$\n\nAnd now `git diff` and `git diff --text` both print:\n\ndiff --cc a.txt\nindex ee95164,d7db2f0..0000000\nBinary files differ\n\n\nBut git diff --text should show how the files differ.\n\nGreetings\n  Дилян\n\nOn Mon, 2021-03-22 at 12:53 +0700, Bagas Sanjaya wrote:\n> \n> \n> On 22/03/21 00.30, Дилян Палаузов wrote:\n> > Hello,\n> > \n> > I create a small text file ending with \\0 and add it to git:\n> \n> Did you mean `echo -e \"\\0\" >> a.txt`?\n> \n> > In .gitattributes I specify:\n> > \n> > *.txt diff merge=text text\n> > \n> > I create several commits by changing the small text file.\n> > \n> > The result is at https://github.com/dilyanpalauzov/git-diff-biinary .\n> > \n> > I do now\n> > \n> >    git rebase -i HEAD~2\n> > and before the “second commit” type E to edit that commit.\n> > \n> > I change the small file.\n> > \n> > git add a.txt && git rebase --continue\n> > \n> > git says:\n> > \n> > [detached HEAD bc00e34] second commit\n> >   Date: Sun Mar 21 19:16:15 2021 +0200\n> >   1 file changed, 2 insertions(+), 1 deletion(-)\n> > warning: Cannot merge binary files: a.txt (HEAD vs. 04c77de (third\n> > commit))\n> > Auto-merging a.txt\n> > CONFLICT (content): Merge conflict in a.txt\n> > error: could not apply 04c77de... third commit\n> > Resolve all conflicts manually, mark them as resolved with\n> > \"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n> > You can instead skip this commit: run \"git rebase --skip\".\n> > To abort and get back to the state before \"git rebase\", run \"git\n> > rebase\n> > --abort\".\n> > Could not apply 04c77de... third commit\n> > \n> > \n> > 'git diff' and 'git diff --text' show:\n> > \n> > diff --cc a.txt\n> > index 7a61015,dc817ec..0000000\n> > --- a/a.txt\n> > +++ b/a.txt\n> > \n> > The file does not contain <<HEAD===>>> markers, despite having\n> > merge=text attribute.\n> > \n> > HOW CAN I force git diff to show the differences and git merge to\n> > include the <<<===>>> markers?\n> > \n> > I have to say, that at different occassions git diff --text does work\n> > ass expected (e.g. when I call git diff --cached --text).\n> > \n> > I call now\n> > git rebase --abort\n> > git log -p\n> > \n> > git shows the differences in the small text file ending with \\0.  So\n> > apparently log reads the option, but diff does not.\n> > \n> > Using git 2.30.2.\n> > \n> > Greetings\n> >    Дилян\n> > \n> \n> Does `file a.txt` shows it as being binary file? I do the similar and\n> it just says \"data\".\n> \n\n\n"},{"id":"420257","messageId":"YF3GDgYSo889TaRJ@coredump.intra.peff.net","threadId":"55363","inReplyTo":"3807b29f442ab7026418511f058ff9513ee200ec.camel@aegee.org","subject":"Re: git diff --text does not work during rebase for binary files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-03-26T11:31:26Z","receivedAt":"2021-03-26T11:32:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 22, 2021 at 10:45:39AM +0200, Дилян Палаузов wrote:\n\n> And now `git diff` and `git diff --text` both print:\n> \n> diff --cc a.txt\n> index ee95164,d7db2f0..0000000\n> Binary files differ\n\nI think the \"combined diff\" code isn't ready to handle the \"--text\"\nflag.\n\nAn easier reproduction than rebase is to just do a merge with a\nconflict:\n\n  git init\n  printf 'base\\0' >file && git add file && git commit -m base\n  printf 'one\\0' >file && git commit -am one\n  git checkout -b side HEAD^\n  printf 'two\\0' >file && git commit -am two\n  git merge master\n\nNow \"git diff --text\" will try to show a combined diff, but it doesn't\nwork. Likewise if you complete the merge:\n\n  printf 'new\\0' >file && git commit -a --no-edit\n\nthen \"git show --text\" will not show a binary combined diff, even though\n\"git show --text HEAD^\" will happily show a normal two-endpoint diff.\n\nCuriously old versions of Git would show broken binary combined diffs,\nuntil 4d5f347199 (combine-diff: handle binary files as binary,\n2011-05-23). So the binary detection there looks mostly sane, but it's\njust not respecting the \"--text\" flag.\n\nSomething like this helps a bit:\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 06635f91bc..940c5c43ff 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1128,6 +1128,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \n \tif (textconv)\n \t\tis_binary = 0;\n+\telse if (opt->flags.text)\n+\t\tis_binary = 0;\n \telse if (userdiff->binary != -1)\n \t\tis_binary = userdiff->binary;\n \telse {\n\nbut I don't think that's the full story. It looks like the combined-diff\ncode is too eager to treat the content as NUL-terminated strings. A\nregular diff shows the NULs:\n\n  $ git show --format= --text HEAD^  | cat -A\n  diff --git a/file b/file$\n  index d249428..a9382c3 100644$\n  --- a/file$\n  +++ b/file$\n  @@ -1 +1 @@$\n  -base^@$\n  \\ No newline at end of file$\n  +two^@$\n  \\ No newline at end of file$\n\nbut the combined diff doesn't:\n\n  $ git show --format= --text HEAD | cat -A\n  diff --cc file$\n  index a9382c3,f33a432..c984a04$\n  --- a/file$\n  +++ b/file$\n  @@@ -1,1 -1,1 +1,1 @@@$\n  - two$\n   -one$\n  ++new$\n\nSo I suspect the code is simply not read to handle the NULs, and the\ncurrent behavior of ignoring --text is better than producing truncated\nor bogus output until those deeper problems are fixed. We could issue a\nwarning that --text was ignored, I suppose, but that doesn't really\nsolve your problem. :)\n\n-Peff\n"}]}