On Mon, Nov 08, 2010 at 10:03:58PM -0500, Jeff King wrote: > > This "However, note that" part should apply not only to newly introduced > > {plus} lines but also to {plus} lines whose change were edited (lines from > > "added content" and from post-image half of "modified content"), no? > > Right. The final paragraph you quoted is not part of the list, and it > looks better when rendered by asciidoc, as it's indented differently. So > I think some of the confusion is from the source formatting. But... In the version below I used asciidoc's "--" block separator. It makes no difference to the formatted output, but hopefully makes the source a little more obvious. > Yeah, some of the operations described in the upper list are actually > "more complex" in the sense of looking like reverts. Basically any time > you are _introducing_ a change during the diff edit rather than simply > selecting or not-selecting changes that exist in the working tree, you > are going to get confusing results. So let me take one more stab at it, > and I think the correct breakdown is: Patch is below. Thanks for bearing with me through all the versions; it turned out to be harder to explain than I thought. :) I think the back and forth has led us to a much more natural organization of the information. -- >8 -- Subject: [PATCH] docs: give more hints about how "add -e" works The previous text was not exactly accurate; it is OK to change space and minus lines, but only in certain ways. This patch takes a whole new approach, which is to describe the sorts of conceptual operations you might want to perform. It also includes a healthy dose of warnings about how things can go wrong. Since the size of the text is getting quite long, it also splits this out into an "editing patches" section. This makes more sense with the current structure, anyway, which already splits out the interactive mode description. Signed-off-by: Jeff King <peff@xxxxxxxx> --- Documentation/git-add.txt | 80 +++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 77 insertions(+), 3 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index 73378b2..54aaaeb 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -92,9 +92,11 @@ See ``Interactive mode'' for details. edit it. After the editor was closed, adjust the hunk headers and apply the patch to the index. + -*NOTE*: Obviously, if you change anything else than the first character -on lines beginning with a space or a minus, the patch will no longer -apply. +The intent of this option is to pick and choose lines of the patch to +apply, or even to modify the contents of lines to be staged. This can be +quicker and more flexible than using the interactive hunk selector. +However, it is easy to confuse oneself and create a patch that does not +apply to the index. See EDITING PATCHES below. -u:: --update:: @@ -295,6 +297,78 @@ diff:: This lets you review what will be committed (i.e. between HEAD and index). + +EDITING PATCHES +--------------- + +Invoking `git add -e` or selecting `e` from the interactive hunk +selector will open a patch in your editor; after the editor exits, the +result is applied to the index. You are free to make arbitrary changes +to the patch, but note that some changes may have confusing results, or +even result in a patch that cannot be applied. If you want to abort the +operation entirely (i.e., stage nothing new in the index), simply delete +all lines of the patch. The list below describes some common things you +may see in a patch, and which editing operations make sense on them. + +-- +added content:: + +Added content is represented by lines beginning with "{plus}". You can +prevent staging any addition lines by deleting them. + +removed content:: + +Removed content is represented by lines beginning with "-". You can +prevent staging their removal by converting the "-" to a " " (space). + +modified content:: + +Modified content is represented by "-" lines (removing the old content) +followed by "{plus}" lines (adding the replacement content). You can +prevent staging the modification by converting "-" lines to " ", and +removing "{plus}" lines. Beware that modifying only half of the pair is +likely to introduce confusing changes to the index. +-- + +There are also more complex operations that can be performed. But beware +that because the patch is applied only to the index and not the working +tree, the working tree will appear to "undo" the change in the index. +For example, introducing a a new line into the index that is in neither +the HEAD nor the working tree will stage the new line for commit, but +the line will appear to be reverted in the working tree. + +Avoid using these constructs, or do so with extreme caution. + +-- +removing untouched content:: + +Content which does not differ between the index and working tree may be +shown on context lines, beginning with a " " (space). You can stage +context lines for removal by converting the space to a "-". The +resulting working tree file will appear to re-add the content. + +modifying existing content:: + +One can also modify context lines by staging them for removal (by +converting " " to "-") and adding a "{plus}" line with the new content. +Similarly, one can modify "{plus}" lines for existing additions or +modifications. In all cases, the new modification will appear reverted +in the working tree. + +new content:: + +You may also add new content that does not exist in the patch; simply +add new lines, each starting with "{plus}". The addition will appear +reverted in the working tree. +-- + +There are also several operations which should be avoided entirely, as +they will make the patch impossible to apply: + +* adding context (" ") or removal ("-") lines +* deleting context or removal lines +* modifying the contents of context or removal lines + SEE ALSO -------- linkgit:git-status[1] -- 1.7.3.2.357.g419a4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html