Skip to content

Commit 54d04f2

Browse files
committed
Merge branch 'jk/add-e-doc' into maint
* jk/add-e-doc: docs: give more hints about how "add -e" works docs: give more hints about how "add -e" works
2 parents 1f238da + 0fe802d commit 54d04f2

File tree

1 file changed

+77
-3
lines changed

1 file changed

+77
-3
lines changed

Documentation/git-add.txt

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ See ``Interactive mode'' for details.
9292
edit it. After the editor was closed, adjust the hunk headers
9393
and apply the patch to the index.
9494
+
95-
*NOTE*: Obviously, if you change anything else than the first character
96-
on lines beginning with a space or a minus, the patch will no longer
97-
apply.
95+
The 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. 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.
98100

99101
-u::
100102
--update::
@@ -295,6 +297,78 @@ diff::
295297
This lets you review what will be committed (i.e. between
296298
HEAD and index).
297299

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+
298372
SEE ALSO
299373
--------
300374
linkgit:git-status[1]

0 commit comments

Comments
 (0)