{"thread":{"id":"49611","subject":"Shouldn't git be able to apply diffs that it created with --ignore-whitespace?","startedAt":"2018-10-18T20:12:25Z","lastAt":"2018-10-20T02:36:23Z","messageCount":2,"participants":["Mahmoud Al-Qudsi","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"360872","messageId":"CACcTrKfVZsRC8y-89mnj6LnRHnT6ivQCHpc0p5ABXk4kds6MbA@mail.gmail.com","threadId":"49611","inReplyTo":null,"subject":"Shouldn't git be able to apply diffs that it created with --ignore-whitespace?","fromName":"Mahmoud Al-Qudsi","fromEmail":"mqudsi@neosmart.net","sentAt":"2018-10-18T20:12:09Z","receivedAt":"2018-10-18T20:12:25Z","isPatch":false,"sender":{"key":"mqudsi@neosmart.net","avatar":"https://gravatar.com/avatar/c2643dd7c6df61aed49d9f3d917ac6d61cafbbda5f9b1619f50d3b749dca415a?d=mp&s=160"},"body":"Hello again all,\n\nI think I've previously broached this subject before, but I think I perhaps\nwasn't clear enough about what I was trying to do or why I feel that git is at\nfault here.\n\n(I'm running git 2.19.1)\n\nStarting with a fully-committed, not-dirty codebase, I open(ed) a poorly\nformatted, mixed-whitespace file (that I absolutely did not author!) under\nversion control and make some very localized changes. My editor, being very\nsmart and helpful, fixes up the line ending on save, and I exit.\n\nAt this point, my source file contains a) deliberate changes I want, and b)\nwhitespace changes I wish I could commit but that should not be a part of my\npatch.\n\nShouldn't the following workflow be supported:\n\n~> git diff -w > foo.diff\n~> git reset --hard\n~> git apply [--ignore-whitespace] < foo.diff\n\nBecause that throws an error in this case:\n\n> error: patch failed: includes/helpers/class.phpmailer.php:1182\n> error: includes/helpers/class.phpmailer.php: patch does not apply\n\nI feel like this did work, once upon a time. Perhaps prior to the same that\nbroke `git add -p` when whitespace was mangled on editor exit/save (2b8ea7f3c7)?\n\nTo help debug this, I'm attaching the output of the following taken after I've\nmade my changes to the file and wish to generate a clean diff, the former of\nwhich applies just fine after `git reset --hard`, while the latter does not:\n\n~> git diff > with_whitespace.diff\n~> git diff -w > without_whitespace.diff\n\n(I can also privately share the original file off-list if needed.)\n\nI don't believe the list allows binary attachments and because we're dealing\nwith line-ending mangling I definitely do not want to include them inline, so\nI've uploaded them here:\n\n* http://share.neosmart.net/View/Index/nGujqm.diff\n* http://share.neosmart.net/View/Index/f4dkVF.diff\n\n(You can download them as-is by clicking the floppy icon in the top-right)\n\nWith thanks,\n\nMahmoud Al-Qudsi\nNeoSmart Technologies\n"},{"id":"360993","messageId":"20181020023612.GO432229@genre.crustytoothpaste.net","threadId":"49611","inReplyTo":"CACcTrKfVZsRC8y-89mnj6LnRHnT6ivQCHpc0p5ABXk4kds6MbA@mail.gmail.com","subject":"Re: Shouldn't git be able to apply diffs that it created with --ignore-whitespace?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-20T02:36:12Z","receivedAt":"2018-10-20T02:36:23Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Thu, Oct 18, 2018 at 03:12:09PM -0500, Mahmoud Al-Qudsi wrote:\n> Hello again all,\n> \n> I think I've previously broached this subject before, but I think I perhaps\n> wasn't clear enough about what I was trying to do or why I feel that git is at\n> fault here.\n> \n> (I'm running git 2.19.1)\n> \n> Starting with a fully-committed, not-dirty codebase, I open(ed) a poorly\n> formatted, mixed-whitespace file (that I absolutely did not author!) under\n> version control and make some very localized changes. My editor, being very\n> smart and helpful, fixes up the line ending on save, and I exit.\n> \n> At this point, my source file contains a) deliberate changes I want, and b)\n> whitespace changes I wish I could commit but that should not be a part of my\n> patch.\n> \n> Shouldn't the following workflow be supported:\n> \n> ~> git diff -w > foo.diff\n> ~> git reset --hard\n> ~> git apply [--ignore-whitespace] < foo.diff\n\nIn general, git diff -w doesn't produce a patch that can be applied.\nThat's because it ignores all whitespace changes in a particular way.\nThe diff output is rendered as if the whitespace in the lines were\nwritten as it is in the postimage (the changed file), not the preimage\n(the original file).\n\nThis is useful because usually if you're, say, indenting a block of\ncode, you want to see the output properly indented with the new lines of\ncode (say, the loop or conditional) you wrote around it.  And since this\nfeature is designed for visual inspection, it makes sense to do it this\nway.  However, it essentially means that your changes can't, in general,\nbe applied.\n\nThere are, of course, situations in which this might have worked in the\npast, and it may indeed work for some situations still, but it won't in\nthe general case.  git apply --ignore-whitespace only modifies context\nlines, so it doesn't affect the actual content lines in the diff.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"}]}