{"thread":{"id":"38664","subject":"git add to ignore whitespaces, some day?","startedAt":"2015-02-27T00:09:30Z","lastAt":"2015-03-04T10:05:50Z","messageCount":2,"participants":["Marc-André Lureau","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"256730","messageId":"CAJ+F1CL_X7d3RayLmohU3tMi6w5juVFEwCEBUA_Nf-Z53bq+ew@mail.gmail.com","threadId":"38664","inReplyTo":null,"subject":"git add to ignore whitespaces, some day?","fromName":"Marc-André Lureau","fromEmail":"marcandre.lureau@gmail.com","sentAt":"2015-02-27T00:09:30Z","receivedAt":"2015-02-27T00:09:30Z","isPatch":false,"sender":{"key":"marcandre.lureau@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9381?v=4"},"body":"Hey,\n\nIt would be nice if git-add could be told to ignore whitespace\nchanges, wouldn't it?\n\nAccording to SO, I am not the one to think so:\nhttp://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes\n\nA change to add--interactive would be as simple as adding the diff -b\nor -w option like:\nmy @diff = run_cmd_pipe(\"git\", @diff_cmd, \"-w\", \"--\", $path);\n\nBut I wonder if this should be configured in a diff.ignorews or passed\nas an argument to git add. Opinions?\n\n-- \nMarc-André Lureau\n"},{"id":"256986","messageId":"20150304100549.GA15788@peff.net","threadId":"38664","inReplyTo":"CAJ+F1CL_X7d3RayLmohU3tMi6w5juVFEwCEBUA_Nf-Z53bq+ew@mail.gmail.com","subject":"Re: git add to ignore whitespaces, some day?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-03-04T10:05:50Z","receivedAt":"2015-03-04T10:05:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 27, 2015 at 01:09:30AM +0100, Marc-André Lureau wrote:\n\n> It would be nice if git-add could be told to ignore whitespace\n> changes, wouldn't it?\n> \n> According to SO, I am not the one to think so:\n> http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes\n> \n> A change to add--interactive would be as simple as adding the diff -b\n> or -w option like:\n> my @diff = run_cmd_pipe(\"git\", @diff_cmd, \"-w\", \"--\", $path);\n\nWhat would it mean to stage such a hunk? For example, consider this\nsituation:\n\n    git init\n\n    echo 'foo();' >file\n    git add file\n\n    {\n      echo 'if (something) {'\n      echo '    foo();'\n      echo '}'\n    } >file\n\nA regular diff shows:\n\n    diff --git a/file b/file\n    index a280f9a..ce0eeda 100644\n    --- a/file\n    +++ b/file\n    @@ -1 +1,3 @@\n    -foo();\n    +if (something) {\n    +    foo();\n    +}\n\nbut \"diff -w\" would show:\n\n    diff --git a/file b/file\n    index a280f9a..ce0eeda 100644\n    --- a/file\n    +++ b/file\n    @@ -1 +1,3 @@\n    +if (something) {\n         foo();\n    +}\n\nIf we try to apply that hunk to what is in the index, it will not work.\nThe context line does not exist in the index file. Even if you could\nconvince git-apply to massage it into place, it still does not update\nthe whitespace in the 'foo();' line. IOW, we did not stage the full hunk\nat all; running \"git add -p\" again would show that we still have the\nwhitespace change to stage.\n\nSo if you were to pursue this, it would have to have two copies of each\nhunk: the one to apply, and the \"display\" copy that we show the user. We\ndo this already for colorization. However, I think we rely there on the\nfact that the two versions of the diff match up, line for line. Whereas\nhere, you would not even necessarily have the same number of hunks\nbetween the regular and \"-b\" versions.\n\n-Peff\n"}]}