{"thread":{"id":"25497","subject":"[PATCH] docs: give more hints about how \"add -e\" works","startedAt":"2010-10-21T14:30:35Z","lastAt":"2010-11-09T04:58:20Z","messageCount":10,"participants":["Jeff King","Jonathan Nieder","Junio C Hamano","Miklos Vajna"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"153966","messageId":"20101021143034.GA16083@sigill.intra.peff.net","threadId":"25497","inReplyTo":null,"subject":"[PATCH] docs: give more hints about how \"add -e\" works","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-21T14:30:35Z","receivedAt":"2010-10-21T14:30:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The previous text was not exactly accurate; it is OK to\nchange space and minus lines, but only in certain ways. This\npatch attempts to cover explicitly what can be done at the\nindividual line level, and cautions the user that\nconceptually larger changes (like modifying a line) require\nsome understanding of the patch format.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nI'm sorting through some old topics in my personal repository and either\nabandoning them or cleaning them up and submitting them. I thought this\none was worth doing. Original thread here:\n\n  http://article.gmane.org/gmane.comp.version-control.git/130345\n\nThis version tries to address your points, Junio. It also seems that the\nformatting issues have been magically fixed upstream in the past year. :)\n\n Documentation/git-add.txt |   32 +++++++++++++++++++++++++++++---\n 1 files changed, 29 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex 73378b2..40deb03 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -92,9 +92,35 @@ See ``Interactive mode'' for details.\n \tedit it.  After the editor was closed, adjust the hunk headers\n \tand apply the patch to the index.\n +\n-*NOTE*: Obviously, if you change anything else than the first character\n-on lines beginning with a space or a minus, the patch will no longer\n-apply.\n+The intent of this option is to pick and choose lines of the patch to\n+apply, or even to modify the contents of lines to be staged. There are\n+three line types in a patch: addition lines (beginning with a plus),\n+removal lines (beginning with a minus), and context lines (beginning\n+with a space). In general, it should be safe to:\n++\n+--\n+* remove addition lines (don't stage the line)\n+* modify the content of any addition lines (stage modified contents)\n+* add new addition lines (stage the new line)\n+* convert context lines to removal lines (stage removal of line)\n+* convert removal lines to context lines (don't stage removal)\n+--\n++\n+Similarly, your patch will likely not apply if you:\n++\n+--\n+* add context or removal lines\n+* delete removal or context lines\n+* modify the contents of context or removal lines\n+--\n++\n+NOTE: In the first list above, the results given for each action are\n+with respect to that patch line only. Conceptual changes like\n+modification of a line in the original file are actually represented by\n+removal of the old line followed by addition of the new line. Deleting\n+only the addition line of this pair but leaving the removal line would\n+therefore convert the modification into a deletion. In other words, use\n+this feature with caution, as it is easy to stage unintended changes.\n \n -u::\n --update::\n-- \n1.7.3.1.235.gdd6c0\n"},{"id":"153998","messageId":"20101021190435.GB11759@burratino","threadId":"25497","inReplyTo":"20101021143034.GA16083@sigill.intra.peff.net","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-21T19:04:35Z","receivedAt":"2010-10-21T19:04:35Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jeff King wrote:\n\n>                                                         This\n> patch attempts to cover explicitly what can be done at the\n> individual line level, and cautions the user that\n> conceptually larger changes (like modifying a line) require\n> some understanding of the patch format.\n\nFor what it's worth:\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n"},{"id":"154039","messageId":"7v4ocftbww.fsf@alter.siamese.dyndns.org","threadId":"25497","inReplyTo":"20101021143034.GA16083@sigill.intra.peff.net","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-21T22:32:15Z","receivedAt":"2010-10-21T22:32:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> -*NOTE*: Obviously, if you change anything else than the first character\n> -on lines beginning with a space or a minus, the patch will no longer\n> -apply.\n\nIt is a good change to lose this \"Obviously\", which is often a sign of the\nlazyness of the author who didn't even bother to explain certain things,\nhandwaving them away as \"Obvious\" ;-)\n\n> +The intent of this option is to pick and choose lines of the patch to\n> +apply, or even to modify the contents of lines to be staged. There are\n> +three line types in a patch: addition lines (beginning with a plus),\n> +removal lines (beginning with a minus), and context lines (beginning\n> +with a space). In general, it should be safe to:\n> ++\n> +--\n> +* remove addition lines (don't stage the line)\n\nI am not sure if the use of the word \"stage\" here is correct, even when\nread from the \"git stage\" lovers' viewpoint.\n\nIf the \"+\" line is a pure addition without any corresponding line in the\npreimage (which is removed by \"-\"), then this is \"Don't add that line\".\nIf it has a corresponding \"-\" line somewhere, that is rather \"Remove\nthe corresponding line in the preimage\".\n\n\"Don't add the updated line\" might be a good compromise.\n\n> +* modify the content of any addition lines (stage modified contents)\n> +* add new addition lines (stage the new line)\n> +* convert context lines to removal lines (stage removal of line)\n> +* convert removal lines to context lines (don't stage removal)\n\nAlternatively, to be consistent with \"stage modification\", \"stage\nremoval\", the removal of \"+\" can be phrased as \"do not stage the addition\nof the line\".\n\nI'd recommend to phrase them as \"don't add\", \"add modified contents\ninstead\", \"add new line\", \"remove line\" and \"do not remove line\", which\nwould be simpler to read, though.\n\n> +Similarly, your patch will likely not apply if you:\n> ++\n> +--\n> +* add context or removal lines\n> +* delete removal or context lines\n> +* modify the contents of context or removal lines\n> +--\n> ++\n> +NOTE: In the first list above, the results given for each action are\n> +with respect to that patch line only. Conceptual changes like\n> +modification of a line in the original file are actually represented by\n> +removal of the old line followed by addition of the new line. Deleting\n> +only the addition line of this pair but leaving the removal line would\n> +therefore convert the modification into a deletion. In other words, use\n> +this feature with caution, as it is easy to stage unintended changes.\n\nIs there a way to move this note way upwards?  Once the reader understands\nwhat this paragraph teaches, it becomes much easier to understand the\nimplication of \"remove addition\".\n"},{"id":"154195","messageId":"20101022192529.GA13059@sigill.intra.peff.net","threadId":"25497","inReplyTo":"7v4ocftbww.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-22T19:25:29Z","receivedAt":"2010-10-22T19:25:29Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 21, 2010 at 03:32:15PM -0700, Junio C Hamano wrote:\n\n> > +The intent of this option is to pick and choose lines of the patch to\n> > +apply, or even to modify the contents of lines to be staged. There are\n> > +three line types in a patch: addition lines (beginning with a plus),\n> > +removal lines (beginning with a minus), and context lines (beginning\n> > +with a space). In general, it should be safe to:\n> > ++\n> > +--\n> > +* remove addition lines (don't stage the line)\n> \n> I am not sure if the use of the word \"stage\" here is correct, even when\n> read from the \"git stage\" lovers' viewpoint.\n> \n> If the \"+\" line is a pure addition without any corresponding line in the\n> preimage (which is removed by \"-\"), then this is \"Don't add that line\".\n> If it has a corresponding \"-\" line somewhere, that is rather \"Remove\n> the corresponding line in the preimage\".\n> \n> \"Don't add the updated line\" might be a good compromise.\n\nI'm not sure that using the word \"add\" here is really any different than\n\"stage\". Because we are really talking about adding _to_ the index,\nwhich to me is the same as staging. IOW, I could say \"Don't stage the\nupdated line\" and it would mean the exact same thing.\n\nIt is a separate issue that adding/staging that line may not be a true\naddition, but rather \"don't add the updated line\". That was what I was\ntrying to address in the final paragraph.\n\nPerhaps the list should be structured not as \"what you can do to each\nline\" but rather \"here are some _concepts_ you might see, here's how\nthey are represented, and how you might want to edit them\". So\nbasically:\n\n  - added lines; represented by \"+\" lines. You can prevent staging any\n    addition lines by deleting them.\n\n  - removed lines; represented by \"-\" lines. You can prevent staging any\n    removal lines by converting \"-\" to \" \".\n\n  - modified lines; represented by \"-\" followed by \"+\". You can prevent\n    staging the modification by converting the \"-\" to a \" \", and\n    removing the \"+\" lines. And this would be a good place to warn that\n    just deleting half of the pair is going to cause problems.\n\n  - existing lines; represented by \" \" lines. You can:\n\n      - remove them, by converting \" \" to \"-\".\n\n      - modify them, by converting \" \" to \"-\", and adding a new \"+\" line\n        with the new content.\n\n  - adding new lines; do not yet exist in the patch. You can add new\n    lines by inserting \"+\" lines with the new content.\n\nwhich is perhaps better, as it directs the user according to what they\nactually want to accomplish.\n\nI shied away from that intially because there are some more complex\ncases (e.g., added lines next to modified lines in the same hunk). But I\nexpect anybody with half a clue can probably figure out how to handle\nthat using the primitives outlined above.\n\n> > +Similarly, your patch will likely not apply if you:\n> > ++\n> > +--\n> > +* add context or removal lines\n> > +* delete removal or context lines\n> > +* modify the contents of context or removal lines\n> > +--\n> > ++\n> > +NOTE: In the first list above, the results given for each action are\n> > +with respect to that patch line only. Conceptual changes like\n> > +modification of a line in the original file are actually represented by\n> > +removal of the old line followed by addition of the new line. Deleting\n> > +only the addition line of this pair but leaving the removal line would\n> > +therefore convert the modification into a deletion. In other words, use\n> > +this feature with caution, as it is easy to stage unintended changes.\n> \n> Is there a way to move this note way upwards?  Once the reader understands\n> what this paragraph teaches, it becomes much easier to understand the\n> implication of \"remove addition\".\n\nI agree it would be better at the top, but I think formatting it as I\njust wrote above would mean we can actually explain the issue in a more\nappropriate place. And then this bottom warning can just go away. I\nthink I may still put a few words of caution at the top.\n\n-Peff\n"},{"id":"154214","messageId":"7v8w1plwq0.fsf@alter.siamese.dyndns.org","threadId":"25497","inReplyTo":"20101022192529.GA13059@sigill.intra.peff.net","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-22T21:54:31Z","receivedAt":"2010-10-22T21:54:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Perhaps the list should be structured not as \"what you can do to each\n> line\" but rather \"here are some _concepts_ you might see, here's how\n> they are represented, and how you might want to edit them\". So\n> basically:\n>\n>   - added lines; represented by \"+\" lines. You can prevent staging any\n>     addition lines by deleting them.\n>\n>   - removed lines; represented by \"-\" lines. You can prevent staging any\n>     removal lines by converting \"-\" to \" \".\n>\n>   - modified lines; represented by \"-\" followed by \"+\". You can prevent\n>     staging the modification by converting the \"-\" to a \" \", and\n>     removing the \"+\" lines. And this would be a good place to warn that\n>     just deleting half of the pair is going to cause problems.\n>\n>   - existing lines; represented by \" \" lines. You can:\n>\n>       - remove them, by converting \" \" to \"-\".\n>\n>       - modify them, by converting \" \" to \"-\", and adding a new \"+\" line\n>         with the new content.\n>\n>   - adding new lines; do not yet exist in the patch. You can add new\n>     lines by inserting \"+\" lines with the new content.\n>\n> which is perhaps better, as it directs the user according to what they\n> actually want to accomplish.\n\nYes, the above reads much better than starting from \"when you see a '+'\nyou can do...\" (which I think is a wrong approach that is backwards).\n\n>> Is there a way to move this note way upwards?  Once the reader understands\n>> what this paragraph teaches, it becomes much easier to understand the\n>> implication of \"remove addition\".\n>\n> I agree it would be better at the top, but I think formatting it as I\n> just wrote above would mean we can actually explain the issue in a more\n> appropriate place. And then this bottom warning can just go away.\n\nAgreed, again.\n"},{"id":"154290","messageId":"20101024003213.GF22105@genesis.frugalware.org","threadId":"25497","inReplyTo":"20101021143034.GA16083@sigill.intra.peff.net","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2010-10-24T00:32:14Z","receivedAt":"2010-10-24T00:32:14Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Thu, Oct 21, 2010 at 10:30:35AM -0400, Jeff King <peff@peff.net> wrote:\n> The previous text was not exactly accurate; it is OK to\n> change space and minus lines, but only in certain ways. This\n> patch attempts to cover explicitly what can be done at the\n> individual line level, and cautions the user that\n> conceptually larger changes (like modifying a line) require\n> some understanding of the patch format.\n\nThanks for collecting those corner cases. :)\n"},{"id":"155442","messageId":"20101108223322.GA12258@sigill.intra.peff.net","threadId":"25497","inReplyTo":"7v8w1plwq0.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-11-08T22:33:23Z","receivedAt":"2010-11-08T22:33:23Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"[long quote, since it has been a few weeks]\n\nOn Fri, Oct 22, 2010 at 02:54:31PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > Perhaps the list should be structured not as \"what you can do to each\n> > line\" but rather \"here are some _concepts_ you might see, here's how\n> > they are represented, and how you might want to edit them\". So\n> > basically:\n> >\n> >   - added lines; represented by \"+\" lines. You can prevent staging any\n> >     addition lines by deleting them.\n> >\n> >   - removed lines; represented by \"-\" lines. You can prevent staging any\n> >     removal lines by converting \"-\" to \" \".\n> >\n> >   - modified lines; represented by \"-\" followed by \"+\". You can prevent\n> >     staging the modification by converting the \"-\" to a \" \", and\n> >     removing the \"+\" lines. And this would be a good place to warn that\n> >     just deleting half of the pair is going to cause problems.\n> >\n> >   - existing lines; represented by \" \" lines. You can:\n> >\n> >       - remove them, by converting \" \" to \"-\".\n> >\n> >       - modify them, by converting \" \" to \"-\", and adding a new \"+\" line\n> >         with the new content.\n> >\n> >   - adding new lines; do not yet exist in the patch. You can add new\n> >     lines by inserting \"+\" lines with the new content.\n> >\n> > which is perhaps better, as it directs the user according to what they\n> > actually want to accomplish.\n> \n> Yes, the above reads much better than starting from \"when you see a '+'\n> you can do...\" (which I think is a wrong approach that is backwards).\n> \n> >> Is there a way to move this note way upwards?  Once the reader understands\n> >> what this paragraph teaches, it becomes much easier to understand the\n> >> implication of \"remove addition\".\n> >\n> > I agree it would be better at the top, but I think formatting it as I\n> > just wrote above would mean we can actually explain the issue in a more\n> > appropriate place. And then this bottom warning can just go away.\n> \n> Agreed, again.\n\nI found a few minutes to look at this today. However, it looks like you\nalready merged my original to next. :) The patch below implements the\nstrategy I discussed above, and IMHO it ended up being much clearer.\n\nIt should replace what's in next. You can either start a new branch and\nrevert what's in next, or I can prepare it on top of what's in next if\nyou prefer.\n\n-- >8 --\nSubject: [PATCH] docs: give more hints about how \"add -e\" works\n\nThe previous text was not exactly accurate; it is OK to\nchange space and minus lines, but only in certain ways.\n\nThis patch takes a whole new approach, which is to describe\nthe sorts of conceptual operations you might want to\nperform. It also includes a healthy dose of warnings about\nhow things can go wrong.\n\nSince the size of the text is getting quite long, it also\nsplits this out into an \"editing patches\" section. This\nmakes more sense with the current structure, anyway, which\nalready splits out the interactive mode description.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/git-add.txt |   63 ++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 60 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex 73378b2..5048309 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -92,9 +92,11 @@ See ``Interactive mode'' for details.\n \tedit it.  After the editor was closed, adjust the hunk headers\n \tand apply the patch to the index.\n +\n-*NOTE*: Obviously, if you change anything else than the first character\n-on lines beginning with a space or a minus, the patch will no longer\n-apply.\n+The intent of this option is to pick and choose lines of the patch to\n+apply, or even to modify the contents of lines to be staged. This can be\n+quicker and more flexible than using the interactive hunk selector.\n+However, it is easy to confuse oneself and create a patch that does not\n+apply to the index. See EDITING PATCHES below.\n \n -u::\n --update::\n@@ -295,6 +297,61 @@ diff::\n   This lets you review what will be committed (i.e. between\n   HEAD and index).\n \n+\n+EDITING PATCHES\n+---------------\n+\n+Invoking `git add -e` or selecting `e` from the interactive hunk\n+selector will open a patch in your editor; after the editor exits, the\n+result is applied to the index. You are free to make arbitrary changes\n+to the patch, but note that only a small subset of possible changes will\n+result in a patch that can be applied. If you want to abort the\n+operation entirely (i.e., stage nothing new in the index), simply delete\n+all lines of the patch. The list below describes common things you may\n+see in a patch, and which editing operations make sense on them.\n+\n+added content::\n+\n+Added content is represented by lines beginning with \"{plus}\". You can\n+prevent staging any addition lines by deleting them.\n+\n+removed content::\n+\n+Removed content is represented by lines beginning with \"-\". You can\n+prevent staging their removal by converting the \"-\" to a \" \" (space).\n+\n+modified content::\n+\n+Modified content is represented by \"-\" lines (removing the old content)\n+followed by \"{plus}\" lines (adding the replacement content). You can\n+prevent staging the modification by converting \"-\" lines to \" \", and\n+removing \"{plus}\" lines. Beware that modifying only half of the pair is\n+likely to introduce confusing changes to the index.\n+\n+untouched content::\n+\n+Untouched content exists in context lines, beginning with a \" \" (space).\n+You can stage context lines for removal by converting the space to a\n+\"-\".\n+\n+new content::\n+\n+You may also add new content that does not exist in the patch. Simply\n+add new lines, each starting with \"{plus}\".\n+\n+You can also perform more complex operations, such as modifying the\n+content to be staged by a \"{plus}\" line. However, note that this impacts\n+_only_ the index; the working tree file will remain unchanged, and will\n+appear to \"undo\" the content you have staged. Such operations should be\n+performed only if you know what you are doing.\n+\n+There are also several operations which should be avoided entirely, as\n+they will make the patch impossible to apply:\n+\n+* adding context (\" \") or removal (\"-\") lines\n+* deleting context or removal lines\n+* modifying the contents of context or removal lines\n+\n SEE ALSO\n --------\n linkgit:git-status[1]\n-- \n1.7.3.2.218.g4ee9d\n"},{"id":"155450","messageId":"7vlj53nwjl.fsf@alter.siamese.dyndns.org","threadId":"25497","inReplyTo":"20101108223322.GA12258@sigill.intra.peff.net","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-09T00:57:34Z","receivedAt":"2010-11-09T00:57:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> It should replace what's in next. You can either start a new branch and\n> revert what's in next, or I can prepare it on top of what's in next if\n> you prefer.\n\nI can just apply an interdiff if I wanted to, so that is no reason for\nasking a resend.\n\nThe new text indeed looks much clearer, except for one part I am not\nabsolutely sure...\n\n> +new content::\n> +\n> +You may also add new content that does not exist in the patch. Simply\n> +add new lines, each starting with \"{plus}\".\n> +\n> +You can also perform more complex operations, such as modifying the\n> +content to be staged by a \"{plus}\" line. However, note that this impacts\n> +_only_ the index; the working tree file will remain unchanged, and will\n> +appear to \"undo\" the content you have staged. Such operations should be\n> +performed only if you know what you are doing.\n\nThis \"However, note that\" part should apply not only to newly introduced\n{plus} lines but also to {plus} lines whose change were edited (lines from\n\"added content\" and from post-image half of \"modified content\"), no?\n\nI tried to be careless when reading the two paragraphs above, and managed\nto get an incorrect impression that the caveat applies only to \"more\ncomplex operations\", even though it actually applies not just the previous\n\"new content\" but also \"added/modified\" content.\n\nThinking about it a bit more, it is worse than that.  Turning \" \" into \"-\"\nhas the same \"getting reverted\" issue, no?\n"},{"id":"155456","messageId":"20101109030358.GA17747@sigill.intra.peff.net","threadId":"25497","inReplyTo":"7vlj53nwjl.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-11-09T03:03:58Z","receivedAt":"2010-11-09T03:03:58Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 08, 2010 at 04:57:34PM -0800, Junio C Hamano wrote:\n\n> The new text indeed looks much clearer, except for one part I am not\n> absolutely sure...\n> \n> > +new content::\n> > +\n> > +You may also add new content that does not exist in the patch. Simply\n> > +add new lines, each starting with \"{plus}\".\n> > +\n> > +You can also perform more complex operations, such as modifying the\n> > +content to be staged by a \"{plus}\" line. However, note that this impacts\n> > +_only_ the index; the working tree file will remain unchanged, and will\n> > +appear to \"undo\" the content you have staged. Such operations should be\n> > +performed only if you know what you are doing.\n> \n> This \"However, note that\" part should apply not only to newly introduced\n> {plus} lines but also to {plus} lines whose change were edited (lines from\n> \"added content\" and from post-image half of \"modified content\"), no?\n\nRight. The final paragraph you quoted is not part of the list, and it\nlooks better when rendered by asciidoc, as it's indented differently. So\nI think some of the confusion is from the source formatting. But...\n\n> I tried to be careless when reading the two paragraphs above, and managed\n> to get an incorrect impression that the caveat applies only to \"more\n> complex operations\", even though it actually applies not just the previous\n> \"new content\" but also \"added/modified\" content.\n> \n> Thinking about it a bit more, it is worse than that.  Turning \" \" into \"-\"\n> has the same \"getting reverted\" issue, no?\n\nYeah, some of the operations described in the upper list are actually\n\"more complex\" in the sense of looking like reverts. Basically any time\nyou are _introducing_ a change during the diff edit rather than simply\nselecting or not-selecting changes that exist in the working tree, you\nare going to get confusing results. So let me take one more stab at it,\nand I think the correct breakdown is:\n\n  1. stuff you might want to do: staging or not staging added, removed,\n     and modified lines\n\n  2. stuff you might want to do if you're insane: marking context lines\n     for removal, adding new content, changing content on existing add\n     lines\n\n  3. stuff that you never want to do, because it makes the patch\n     impossible to apply: deleting, adding, or changing context or\n     removal lines\n\nI'll try to do a patch later tonight.\n\n-Peff\n"},{"id":"155458","messageId":"20101109045820.GA19728@sigill.intra.peff.net","threadId":"25497","inReplyTo":"20101109030358.GA17747@sigill.intra.peff.net","subject":"Re: [PATCH] docs: give more hints about how \"add -e\" works","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-11-09T04:58:20Z","receivedAt":"2010-11-09T04:58:20Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 08, 2010 at 10:03:58PM -0500, Jeff King wrote:\n\n> > This \"However, note that\" part should apply not only to newly introduced\n> > {plus} lines but also to {plus} lines whose change were edited (lines from\n> > \"added content\" and from post-image half of \"modified content\"), no?\n> \n> Right. The final paragraph you quoted is not part of the list, and it\n> looks better when rendered by asciidoc, as it's indented differently. So\n> I think some of the confusion is from the source formatting. But...\n\nIn the version below I used asciidoc's \"--\" block separator. It makes no\ndifference to the formatted output, but hopefully makes the source a\nlittle more obvious.\n\n> Yeah, some of the operations described in the upper list are actually\n> \"more complex\" in the sense of looking like reverts. Basically any time\n> you are _introducing_ a change during the diff edit rather than simply\n> selecting or not-selecting changes that exist in the working tree, you\n> are going to get confusing results. So let me take one more stab at it,\n> and I think the correct breakdown is:\n\nPatch is below. Thanks for bearing with me through all the versions; it\nturned out to be harder to explain than I thought. :) I think the back\nand forth has led us to a much more natural organization of the\ninformation.\n\n-- >8 --\nSubject: [PATCH] docs: give more hints about how \"add -e\" works\n\nThe previous text was not exactly accurate; it is OK to\nchange space and minus lines, but only in certain ways.\n\nThis patch takes a whole new approach, which is to describe\nthe sorts of conceptual operations you might want to\nperform. It also includes a healthy dose of warnings about\nhow things can go wrong.\n\nSince the size of the text is getting quite long, it also\nsplits this out into an \"editing patches\" section. This\nmakes more sense with the current structure, anyway, which\nalready splits out the interactive mode description.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/git-add.txt |   80 +++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 77 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex 73378b2..54aaaeb 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -92,9 +92,11 @@ See ``Interactive mode'' for details.\n \tedit it.  After the editor was closed, adjust the hunk headers\n \tand apply the patch to the index.\n +\n-*NOTE*: Obviously, if you change anything else than the first character\n-on lines beginning with a space or a minus, the patch will no longer\n-apply.\n+The intent of this option is to pick and choose lines of the patch to\n+apply, or even to modify the contents of lines to be staged. This can be\n+quicker and more flexible than using the interactive hunk selector.\n+However, it is easy to confuse oneself and create a patch that does not\n+apply to the index. See EDITING PATCHES below.\n \n -u::\n --update::\n@@ -295,6 +297,78 @@ diff::\n   This lets you review what will be committed (i.e. between\n   HEAD and index).\n \n+\n+EDITING PATCHES\n+---------------\n+\n+Invoking `git add -e` or selecting `e` from the interactive hunk\n+selector will open a patch in your editor; after the editor exits, the\n+result is applied to the index. You are free to make arbitrary changes\n+to the patch, but note that some changes may have confusing results, or\n+even result in a patch that cannot be applied.  If you want to abort the\n+operation entirely (i.e., stage nothing new in the index), simply delete\n+all lines of the patch. The list below describes some common things you\n+may see in a patch, and which editing operations make sense on them.\n+\n+--\n+added content::\n+\n+Added content is represented by lines beginning with \"{plus}\". You can\n+prevent staging any addition lines by deleting them.\n+\n+removed content::\n+\n+Removed content is represented by lines beginning with \"-\". You can\n+prevent staging their removal by converting the \"-\" to a \" \" (space).\n+\n+modified content::\n+\n+Modified content is represented by \"-\" lines (removing the old content)\n+followed by \"{plus}\" lines (adding the replacement content). You can\n+prevent staging the modification by converting \"-\" lines to \" \", and\n+removing \"{plus}\" lines. Beware that modifying only half of the pair is\n+likely to introduce confusing changes to the index.\n+--\n+\n+There are also more complex operations that can be performed. But beware\n+that because the patch is applied only to the index and not the working\n+tree, the working tree will appear to \"undo\" the change in the index.\n+For example, introducing a a new line into the index that is in neither\n+the HEAD nor the working tree will stage the new line for commit, but\n+the line will appear to be reverted in the working tree.\n+\n+Avoid using these constructs, or do so with extreme caution.\n+\n+--\n+removing untouched content::\n+\n+Content which does not differ between the index and working tree may be\n+shown on context lines, beginning with a \" \" (space).  You can stage\n+context lines for removal by converting the space to a \"-\". The\n+resulting working tree file will appear to re-add the content.\n+\n+modifying existing content::\n+\n+One can also modify context lines by staging them for removal (by\n+converting \" \" to \"-\") and adding a \"{plus}\" line with the new content.\n+Similarly, one can modify \"{plus}\" lines for existing additions or\n+modifications. In all cases, the new modification will appear reverted\n+in the working tree.\n+\n+new content::\n+\n+You may also add new content that does not exist in the patch; simply\n+add new lines, each starting with \"{plus}\". The addition will appear\n+reverted in the working tree.\n+--\n+\n+There are also several operations which should be avoided entirely, as\n+they will make the patch impossible to apply:\n+\n+* adding context (\" \") or removal (\"-\") lines\n+* deleting context or removal lines\n+* modifying the contents of context or removal lines\n+\n SEE ALSO\n --------\n linkgit:git-status[1]\n-- \n1.7.3.2.357.g419a4\n"}]}