@@ -93,34 +93,10 @@ See ``Interactive mode'' for details.
9393 and apply the patch to the index.
9494+
9595The intent of this option is to pick and choose lines of the patch to
96- apply, or even to modify the contents of lines to be staged. There are
97- three line types in a patch: addition lines (beginning with a plus),
98- removal lines (beginning with a minus), and context lines (beginning
99- with a space). In general, it should be safe to:
100- +
101- --
102- * remove addition lines (don't stage the line)
103- * modify the content of any addition lines (stage modified contents)
104- * add new addition lines (stage the new line)
105- * convert context lines to removal lines (stage removal of line)
106- * convert removal lines to context lines (don't stage removal)
107- --
108- +
109- Similarly, your patch will likely not apply if you:
110- +
111- --
112- * add context or removal lines
113- * delete removal or context lines
114- * modify the contents of context or removal lines
115- --
116- +
117- NOTE: In the first list above, the results given for each action are
118- with respect to that patch line only. Conceptual changes like
119- modification of a line in the original file are actually represented by
120- removal of the old line followed by addition of the new line. Deleting
121- only the addition line of this pair but leaving the removal line would
122- therefore convert the modification into a deletion. In other words, use
123- this feature with caution, as it is easy to stage unintended changes.
96+ apply, or even to modify the contents of lines to be staged. This can be
97+ quicker and more flexible than using the interactive hunk selector.
98+ However, it is easy to confuse oneself and create a patch that does not
99+ apply to the index. See EDITING PATCHES below.
124100
125101-u::
126102--update::
@@ -321,6 +297,78 @@ diff::
321297 This lets you review what will be committed (i.e. between
322298 HEAD and index).
323299
300+
301+ EDITING PATCHES
302+ ---------------
303+
304+ Invoking `git add -e` or selecting `e` from the interactive hunk
305+ selector will open a patch in your editor; after the editor exits, the
306+ result is applied to the index. You are free to make arbitrary changes
307+ to the patch, but note that some changes may have confusing results, or
308+ even result in a patch that cannot be applied. If you want to abort the
309+ operation entirely (i.e., stage nothing new in the index), simply delete
310+ all lines of the patch. The list below describes some common things you
311+ may see in a patch, and which editing operations make sense on them.
312+
313+ --
314+ added content::
315+
316+ Added content is represented by lines beginning with "{plus}". You can
317+ prevent staging any addition lines by deleting them.
318+
319+ removed content::
320+
321+ Removed content is represented by lines beginning with "-". You can
322+ prevent staging their removal by converting the "-" to a " " (space).
323+
324+ modified content::
325+
326+ Modified content is represented by "-" lines (removing the old content)
327+ followed by "{plus}" lines (adding the replacement content). You can
328+ prevent staging the modification by converting "-" lines to " ", and
329+ removing "{plus}" lines. Beware that modifying only half of the pair is
330+ likely to introduce confusing changes to the index.
331+ --
332+
333+ There are also more complex operations that can be performed. But beware
334+ that because the patch is applied only to the index and not the working
335+ tree, the working tree will appear to "undo" the change in the index.
336+ For example, introducing a a new line into the index that is in neither
337+ the HEAD nor the working tree will stage the new line for commit, but
338+ the line will appear to be reverted in the working tree.
339+
340+ Avoid using these constructs, or do so with extreme caution.
341+
342+ --
343+ removing untouched content::
344+
345+ Content which does not differ between the index and working tree may be
346+ shown on context lines, beginning with a " " (space). You can stage
347+ context lines for removal by converting the space to a "-". The
348+ resulting working tree file will appear to re-add the content.
349+
350+ modifying existing content::
351+
352+ One can also modify context lines by staging them for removal (by
353+ converting " " to "-") and adding a "{plus}" line with the new content.
354+ Similarly, one can modify "{plus}" lines for existing additions or
355+ modifications. In all cases, the new modification will appear reverted
356+ in the working tree.
357+
358+ new content::
359+
360+ You may also add new content that does not exist in the patch; simply
361+ add new lines, each starting with "{plus}". The addition will appear
362+ reverted in the working tree.
363+ --
364+
365+ There are also several operations which should be avoided entirely, as
366+ they will make the patch impossible to apply:
367+
368+ * adding context (" ") or removal ("-") lines
369+ * deleting context or removal lines
370+ * modifying the contents of context or removal lines
371+
324372SEE ALSO
325373--------
326374linkgit:git-status[1]
0 commit comments