{"thread":{"id":"18794","subject":"[PATCH] git-add: introduce --edit (to edit the diff vs. the index)","startedAt":"2009-04-08T21:30:24Z","lastAt":"2009-04-13T16:59:43Z","messageCount":11,"participants":["Johannes Schindelin","Sverre Rabbelier","Ping Yin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"110873","messageId":"61c07126e28aba0a36730da06112bd2d16eabc1b.1239225986u.git.johannes.schindelin@gmx.de","threadId":"18794","inReplyTo":"cover.1239225986u.git.johannes.schindelin@gmx.de","subject":"[PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-08T21:30:24Z","receivedAt":"2009-04-08T21:30:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"With \"git add -e [<files>]\", Git will fire up an editor with the current\ndiff relative to the index (i.e. what you would get with \"git diff\n[<files>]\").\n\nNow you can edit the patch as much as you like, including adding/removing\nlines, editing the text, whatever.  Make sure, though, that the first\ncharacter of the hunk lines is still a space, a plus or a minus.\n\nAfter you closed the editor, Git will adjust the line counts of the hunks \nif necessary, thanks to the --recount option of apply, and commit the \npatch.  Except if you deleted everything, in which case nothing happens \n(for obvious reasons).\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI actually promised myself not to resend this patch, but a \n\tcertain guy who has a hat now asked for it.\n\n Documentation/git-add.txt |   11 ++++-\n builtin-add.c             |   59 +++++++++++++++++++++++-\n t/t3702-add-edit.sh       |  109 +++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 175 insertions(+), 4 deletions(-)\n create mode 100755 t/t3702-add-edit.sh\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex ce71838..25e6667 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -9,7 +9,7 @@ SYNOPSIS\n --------\n [verse]\n 'git add' [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]\n-\t  [--all | [--update | -u]] [--intent-to-add | -N]\n+\t  [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]\n \t  [--refresh] [--ignore-errors] [--] <filepattern>...\n \n DESCRIPTION\n@@ -76,6 +76,15 @@ OPTIONS\n \tbypassed and the 'patch' subcommand is invoked using each of\n \tthe specified filepatterns before exiting.\n \n+-e, \\--edit::\n+\tOpen the diff vs. the index in an editor and let the user\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+\n -u::\n --update::\n \tUpdate only files that git already knows about, staging modified\ndiff --git a/builtin-add.c b/builtin-add.c\nindex cb67d2c..e931974 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -10,12 +10,14 @@\n #include \"cache-tree.h\"\n #include \"run-command.h\"\n #include \"parse-options.h\"\n+#include \"diff.h\"\n+#include \"revision.h\"\n \n static const char * const builtin_add_usage[] = {\n \t\"git add [options] [--] <filepattern>...\",\n \tNULL\n };\n-static int patch_interactive, add_interactive;\n+static int patch_interactive, add_interactive, edit_interactive;\n static int take_worktree_changes;\n \n static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)\n@@ -187,6 +189,51 @@ int interactive_add(int argc, const char **argv, const char *prefix)\n \treturn status;\n }\n \n+int edit_patch(int argc, const char **argv, const char *prefix)\n+{\n+\tchar *file = xstrdup(git_path(\"ADD_EDIT.patch\"));\n+\tconst char *apply_argv[] = { \"apply\", \"--recount\", \"--cached\",\n+\t\tfile, NULL };\n+\tstruct child_process child;\n+\tstruct rev_info rev;\n+\tint out;\n+\tstruct stat st;\n+\n+\tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n+\n+\tif (read_cache() < 0)\n+\t\tdie (\"Could not read the index\");\n+\n+\tinit_revisions(&rev, prefix);\n+\trev.diffopt.context = 7;\n+\n+\targc = setup_revisions(argc, argv, &rev, NULL);\n+\trev.diffopt.output_format = DIFF_FORMAT_PATCH;\n+\tout = open(file, O_CREAT | O_WRONLY, 0644);\n+\tif (out < 0)\n+\t\tdie (\"Could not open '%s' for writing.\", file);\n+\trev.diffopt.file = fdopen(out, \"w\");\n+\trev.diffopt.close_file = 1;\n+\tif (run_diff_files(&rev, 0))\n+\t\tdie (\"Could not write patch\");\n+\n+\tlaunch_editor(file, NULL, NULL);\n+\n+\tif (stat(file, &st))\n+\t\tdie(\"Could not stat '%s'\", file);\n+\tif (!st.st_size)\n+\t\tdie(\"Empty patch. Aborted.\");\n+\n+\tmemset(&child, 0, sizeof(child));\n+\tchild.git_cmd = 1;\n+\tchild.argv = apply_argv;\n+\tif (run_command(&child))\n+\t\tdie (\"Could not apply '%s'\", file);\n+\n+\tunlink(file);\n+\treturn 0;\n+}\n+\n static struct lock_file lock_file;\n \n static const char ignore_error[] =\n@@ -201,6 +248,7 @@ static struct option builtin_add_options[] = {\n \tOPT_GROUP(\"\"),\n \tOPT_BOOLEAN('i', \"interactive\", &add_interactive, \"interactive picking\"),\n \tOPT_BOOLEAN('p', \"patch\", &patch_interactive, \"interactive patching\"),\n+\tOPT_BOOLEAN('e', \"edit\", &edit_interactive, \"super-interactive patching\"),\n \tOPT_BOOLEAN('f', \"force\", &ignored_too, \"allow adding otherwise ignored files\"),\n \tOPT_BOOLEAN('u', \"update\", &take_worktree_changes, \"update tracked files\"),\n \tOPT_BOOLEAN('N', \"intent-to-add\", &intent_to_add, \"record only the fact that the path will be added later\"),\n@@ -251,14 +299,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tint require_pathspec;\n \n \targc = parse_options(argc, argv, builtin_add_options,\n-\t\t\t  builtin_add_usage, 0);\n+\t\t\t  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);\n \tif (patch_interactive)\n \t\tadd_interactive = 1;\n \tif (add_interactive)\n-\t\texit(interactive_add(argc, argv, prefix));\n+\t\texit(interactive_add(argc - 1, argv + 1, prefix));\n \n \tgit_config(add_config, NULL);\n \n+\tif (edit_interactive)\n+\t\treturn(edit_patch(argc, argv, prefix));\n+\targc--;\n+\targv++;\n+\n \tif (addremove && take_worktree_changes)\n \t\tdie(\"-A and -u are mutually incompatible\");\n \tif ((addremove || take_worktree_changes) && !argc) {\ndiff --git a/t/t3702-add-edit.sh b/t/t3702-add-edit.sh\nnew file mode 100755\nindex 0000000..7262786\n--- /dev/null\n+++ b/t/t3702-add-edit.sh\n@@ -0,0 +1,109 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Johannes E. Schindelin\n+#\n+\n+test_description='add -e basic tests'\n+. ./test-lib.sh\n+\n+\n+cat > file << EOF\n+LO, praise of the prowess of people-kings\n+of spear-armed Danes, in days long sped,\n+we have heard, and what honor the athelings won!\n+Oft Scyld the Scefing from squadroned foes,\n+from many a tribe, the mead-bench tore,\n+awing the earls. Since erst he lay\n+friendless, a foundling, fate repaid him:\n+for he waxed under welkin, in wealth he throve,\n+till before him the folk, both far and near,\n+who house by the whale-path, heard his mandate,\n+gave him gifts:  a good king he!\n+EOF\n+\n+test_expect_success 'setup' '\n+\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m initial file\n+\n+'\n+\n+cat > expected-patch << EOF\n+diff --git a/file b/file\n+index b9834b5..0b8f197 100644\n+--- a/file\n++++ b/file\n+@@ -1,11 +1,3 @@\n+-LO, praise of the prowess of people-kings\n+-of spear-armed Danes, in days long sped,\n+-we have heard, and what honor the athelings won!\n+-Oft Scyld the Scefing from squadroned foes,\n+-from many a tribe, the mead-bench tore,\n+-awing the earls. Since erst he lay\n+-friendless, a foundling, fate repaid him:\n+-for he waxed under welkin, in wealth he throve,\n+-till before him the folk, both far and near,\n+-who house by the whale-path, heard his mandate,\n+-gave him gifts:  a good king he!\n++#!$SHELL_PATH\n++mv -f \"\\$1\" orig-patch &&\n++mv -f patch \"\\$1\"\n+EOF\n+\n+cat > patch << EOF\n+diff --git a/file b/file\n+index b9834b5..ef6e94c 100644\n+--- a/file\n++++ b/file\n+@@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped,\n+ we have heard, and what honor the athelings won!\n++\n+ Oft Scyld the Scefing from squadroned foes,\n+@@ -2,7 +1,5 @@ awing the earls. Since erst he lay\n+ friendless, a foundling, fate repaid him:\n++\n+ for he waxed under welkin, in wealth he throve,\n+EOF\n+\n+cat > expected << EOF\n+diff --git a/file b/file\n+index b9834b5..ef6e94c 100644\n+--- a/file\n++++ b/file\n+@@ -1,10 +1,12 @@\n+ LO, praise of the prowess of people-kings\n+ of spear-armed Danes, in days long sped,\n+ we have heard, and what honor the athelings won!\n++\n+ Oft Scyld the Scefing from squadroned foes,\n+ from many a tribe, the mead-bench tore,\n+ awing the earls. Since erst he lay\n+ friendless, a foundling, fate repaid him:\n++\n+ for he waxed under welkin, in wealth he throve,\n+ till before him the folk, both far and near,\n+ who house by the whale-path, heard his mandate,\n+EOF\n+\n+echo \"#!$SHELL_PATH\" >fake-editor.sh\n+cat >> fake-editor.sh <<\\EOF\n+mv -f \"$1\" orig-patch &&\n+mv -f patch \"$1\"\n+EOF\n+\n+test_set_editor \"$(pwd)/fake-editor.sh\"\n+chmod a+x fake-editor.sh\n+\n+test_expect_success 'add -e' '\n+\n+\tcp fake-editor.sh file &&\n+\tgit add -e &&\n+\ttest_cmp fake-editor.sh file &&\n+\ttest_cmp orig-patch expected-patch &&\n+\tgit diff --cached > out &&\n+\ttest_cmp out expected\n+\n+'\n+\n+test_done\n-- \n1.6.2.1.613.g25746\n"},{"id":"110874","messageId":"fabb9a1e0904081432x57b6811bubb6a40237710a3d6@mail.gmail.com","threadId":"18794","inReplyTo":"61c07126e28aba0a36730da06112bd2d16eabc1b.1239225986u.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-04-08T21:32:03Z","receivedAt":"2009-04-08T21:32:03Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Apr 8, 2009 at 23:30, Johannes Schindelin <johannes.schindelin@gmx.de> >\n>        I actually promised myself not to resend this patch, but a\n>        certain guy who has a hat now asked for it.\n\nWhoever it may be that asked you for it, I am glad they did! It's\nreally nice to help massage a patch series into shape. I'm a big fan\nof 'git add -p', this would seem like the logical compliment to it imo\n:).\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"110885","messageId":"46dff0320904081900n7bff2280rc49315e3db427919@mail.gmail.com","threadId":"18794","inReplyTo":"61c07126e28aba0a36730da06112bd2d16eabc1b.1239225986u.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-04-09T02:00:25Z","receivedAt":"2009-04-09T02:00:25Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Thu, Apr 9, 2009 at 5:30 AM, Johannes Schindelin\n<johannes.schindelin@gmx.de> wrote:\n> With \"git add -e [<files>]\", Git will fire up an editor with the current\n> diff relative to the index (i.e. what you would get with \"git diff\n> [<files>]\").\n>\n> Now you can edit the patch as much as you like, including adding/removing\n> lines, editing the text, whatever.  Make sure, though, that the first\n> character of the hunk lines is still a space, a plus or a minus.\n>\n> After you closed the editor, Git will adjust the line counts of the hunks\n> if necessary, thanks to the --recount option of apply, and commit the\n> patch.  Except if you deleted everything, in which case nothing happens\n> (for obvious reasons).\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>\n>        I actually promised myself not to resend this patch, but a\n>        certain guy who has a hat now asked for it.\n>\n\nI am that guy :-). Thanks. Sometimes \"add -e\" is more useful than \"add\n-p\" since i can see the full context when editing the patch. However,\nsometimes the ability to edit the index directly is even more useful.\nFor example, if it's a big change (or rewritten), it is hard to edit\nthe patch instead of the index (in diff mode with the worktree file\nside by side). I even encounter a case that i can't beat the patch\ninto a shape i want when using 'add -p'  ( it will fail to apply)\n"},{"id":"110981","messageId":"46dff0320904091843p3e034647j3c78506b4d0c2b4@mail.gmail.com","threadId":"18794","inReplyTo":"46dff0320904081900n7bff2280rc49315e3db427919@mail.gmail.com","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-04-10T01:43:59Z","receivedAt":"2009-04-10T01:43:59Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Thu, Apr 9, 2009 at 10:00 AM, Ping Yin <pkufranky@gmail.com> wrote:\n> On Thu, Apr 9, 2009 at 5:30 AM, Johannes Schindelin\n> <johannes.schindelin@gmx.de> wrote:\n>> With \"git add -e [<files>]\", Git will fire up an editor with the current\n>> diff relative to the index (i.e. what you would get with \"git diff\n>> [<files>]\").\n>>\n>> Now you can edit the patch as much as you like, including adding/removing\n>> lines, editing the text, whatever.  Make sure, though, that the first\n>> character of the hunk lines is still a space, a plus or a minus.\n>>\n>> After you closed the editor, Git will adjust the line counts of the hunks\n>> if necessary, thanks to the --recount option of apply, and commit the\n>> patch.  Except if you deleted everything, in which case nothing happens\n>> (for obvious reasons).\n>>\n>> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>> ---\n>>\n>>        I actually promised myself not to resend this patch, but a\n>>        certain guy who has a hat now asked for it.\n>>\n>\n> I am that guy :-). Thanks. Sometimes \"add -e\" is more useful than \"add\n> -p\" since i can see the full context when editing the patch. However,\n> sometimes the ability to edit the index directly is even more useful.\n> For example, if it's a big change (or rewritten), it is hard to edit\n> the patch instead of the index (in diff mode with the worktree file\n> side by side). I even encounter a case that i can't beat the patch\n> into a shape i want when using 'add -p'  ( it will fail to apply)\n>\n\nHow about this?\n 'add --edit=patch' to edit the patch and \"add --edit=index\" to edit the index\n"},{"id":"110982","messageId":"46dff0320904091903p57df51c8ice90648ab7a4baa6@mail.gmail.com","threadId":"18794","inReplyTo":"46dff0320904091843p3e034647j3c78506b4d0c2b4@mail.gmail.com","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-04-10T02:03:19Z","receivedAt":"2009-04-10T02:03:19Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Fri, Apr 10, 2009 at 9:43 AM, Ping Yin <pkufranky@gmail.com> wrote:\n\n> How about this?\n>  'add --edit=patch' to edit the patch and \"add --edit=index\" to edit the index\n>\n\nOne usecase for edit index\n\nAfter a big change in foo.c in the worktree, you find a typo in foo.c.\nYou want to fix the typo first before commit the big change. But the\nchange is so big that you can't just fix the typo in worktree foo.c\nand then use \"add -p\" to pick the typo fix first.\n\nSo you can\n\ngit stash\nfix typo and commit\ngit stash apply and resolve the conflict\n\nWith 'add --edit=patch', you can\ngit add --edit=patch foo.c\n\nan editor is fired up with the foo.c in index and worktree open side\nby side. And you can fix the typo in both index and worktree file.\nWhen exiting the editor, the index file is modified, and no conflict\nto resolve.\n"},{"id":"111018","messageId":"alpine.DEB.1.00.0904102009440.10279@pacific.mpi-cbg.de","threadId":"18794","inReplyTo":"46dff0320904091843p3e034647j3c78506b4d0c2b4@mail.gmail.com","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-10T18:10:36Z","receivedAt":"2009-04-10T18:10:36Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 10 Apr 2009, Ping Yin wrote:\n\n> On Thu, Apr 9, 2009 at 10:00 AM, Ping Yin <pkufranky@gmail.com> wrote:\n> > On Thu, Apr 9, 2009 at 5:30 AM, Johannes Schindelin\n> > <johannes.schindelin@gmx.de> wrote:\n> >> With \"git add -e [<files>]\", Git will fire up an editor with the current\n> >> diff relative to the index (i.e. what you would get with \"git diff\n> >> [<files>]\").\n> >>\n> >> Now you can edit the patch as much as you like, including adding/removing\n> >> lines, editing the text, whatever.  Make sure, though, that the first\n> >> character of the hunk lines is still a space, a plus or a minus.\n> >>\n> >> After you closed the editor, Git will adjust the line counts of the hunks\n> >> if necessary, thanks to the --recount option of apply, and commit the\n> >> patch.  Except if you deleted everything, in which case nothing happens\n> >> (for obvious reasons).\n> >>\n> >> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >> ---\n> >>\n> >>        I actually promised myself not to resend this patch, but a\n> >>        certain guy who has a hat now asked for it.\n> >>\n> >\n> > I am that guy :-). Thanks. Sometimes \"add -e\" is more useful than \"add\n> > -p\" since i can see the full context when editing the patch. However,\n> > sometimes the ability to edit the index directly is even more useful.\n> > For example, if it's a big change (or rewritten), it is hard to edit\n> > the patch instead of the index (in diff mode with the worktree file\n> > side by side). I even encounter a case that i can't beat the patch\n> > into a shape i want when using 'add -p'  ( it will fail to apply)\n> >\n> \n> How about this?\n>  'add --edit=patch' to edit the patch and \"add --edit=index\" to edit the index\n\nAs others have mentioned, there _is_ a reason we have a working directory.  \nPlease understand this as a \"I do not like the idea of editing the index \ndirectly at all\".\n\nCiao,\nDscho\n"},{"id":"111024","messageId":"fabb9a1e0904101159w7ab19247k81f4b67b8a91198f@mail.gmail.com","threadId":"18794","inReplyTo":"alpine.DEB.1.00.0904102009440.10279@pacific.mpi-cbg.de","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-04-10T18:59:34Z","receivedAt":"2009-04-10T18:59:34Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Fri, Apr 10, 2009 at 20:10, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> > As others have mentioned, there _is_ a\nreason we have a working directory.\n> Please understand this as a \"I do not like the idea of editing the index\n> directly at all\".\n\nI do not intend use it as a replacement of the working directory, but\nmostly as a way to split up patches easier. Mainly to _remove_ lines\nthat I staged that I would like to be in a different patch in the\nseries (possibly after doing 'git reset --soft'). I always go through\nmy a longer patch series multiple times until I am satisfied with the\nresult, this addition would make that a lot easier.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"111034","messageId":"46dff0320904101811g3b5dcc8ag195d40005b181c52@mail.gmail.com","threadId":"18794","inReplyTo":"alpine.DEB.1.00.0904102009440.10279@pacific.mpi-cbg.de","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-04-11T01:11:12Z","receivedAt":"2009-04-11T01:11:12Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Sat, Apr 11, 2009 at 2:10 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Fri, 10 Apr 2009, Ping Yin wrote:\n>\n>> On Thu, Apr 9, 2009 at 10:00 AM, Ping Yin <pkufranky@gmail.com> wrote:\n>> > On Thu, Apr 9, 2009 at 5:30 AM, Johannes Schindelin\n>> > <johannes.schindelin@gmx.de> wrote:\n>> >> With \"git add -e [<files>]\", Git will fire up an editor with the current\n>> >> diff relative to the index (i.e. what you would get with \"git diff\n>> >> [<files>]\").\n>> >>\n>> >> Now you can edit the patch as much as you like, including adding/removing\n>> >> lines, editing the text, whatever.  Make sure, though, that the first\n>> >> character of the hunk lines is still a space, a plus or a minus.\n>> >>\n>> >> After you closed the editor, Git will adjust the line counts of the hunks\n>> >> if necessary, thanks to the --recount option of apply, and commit the\n>> >> patch.  Except if you deleted everything, in which case nothing happens\n>> >> (for obvious reasons).\n>> >>\n>> >> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>> >> ---\n>> >>\n>> >>        I actually promised myself not to resend this patch, but a\n>> >>        certain guy who has a hat now asked for it.\n>> >>\n>> >\n>> > I am that guy :-). Thanks. Sometimes \"add -e\" is more useful than \"add\n>> > -p\" since i can see the full context when editing the patch. However,\n>> > sometimes the ability to edit the index directly is even more useful.\n>> > For example, if it's a big change (or rewritten), it is hard to edit\n>> > the patch instead of the index (in diff mode with the worktree file\n>> > side by side). I even encounter a case that i can't beat the patch\n>> > into a shape i want when using 'add -p'  ( it will fail to apply)\n>> >\n>>\n>> How about this?\n>>  'add --edit=patch' to edit the patch and \"add --edit=index\" to edit the index\n>\n> As others have mentioned, there _is_ a reason we have a working directory.\n> Please understand this as a \"I do not like the idea of editing the index\n> directly at all\".\n>\n\nWhen doing \"add --edit\" to edit the patch, do you work on the working\ndirectory? I think they are just different ways to change the index?\n"},{"id":"111194","messageId":"alpine.DEB.1.00.0904131817160.10279@pacific.mpi-cbg.de","threadId":"18794","inReplyTo":"fabb9a1e0904101159w7ab19247k81f4b67b8a91198f@mail.gmail.com","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-13T16:19:51Z","receivedAt":"2009-04-13T16:19:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 10 Apr 2009, Sverre Rabbelier wrote:\n\n> On Fri, Apr 10, 2009 at 20:10, Johannes Schindelin \n> <Johannes.Schindelin@gmx.de> > As others have mentioned, there _is_ a \n> reason we have a working directory.\n> > Please understand this as a \"I do not like the idea of editing the \n> > index directly at all\".\n> \n> I do not intend use it as a replacement of the working directory, but \n> mostly as a way to split up patches easier. Mainly to _remove_ lines \n> that I staged that I would like to be in a different patch in the series \n> (possibly after doing 'git reset --soft'). I always go through my a \n> longer patch series multiple times until I am satisfied with the result, \n> this addition would make that a lot easier.\n\nWould not a much saner way be\n\n\t$ git reset HEAD^\n\t$ git add -p\n\t$ git stash save --keep-index\n\t# test it\n\t$ git commit\n\t$ git stash apply\n\t# test again\n\t$ git commit\n\nHmm?\n\nBTW I do not like the \"longness\" of \"git stash save --keep-index\"; of \ncourse I could install an alias for that, but it feels wrong to have only \na cumbersome to call something that should be part of a _lot_ of \nworkflows.\n\nCiao,\nDscho\n"},{"id":"111195","messageId":"alpine.DEB.1.00.0904131820260.10279@pacific.mpi-cbg.de","threadId":"18794","inReplyTo":"46dff0320904101811g3b5dcc8ag195d40005b181c52@mail.gmail.com","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-13T16:21:19Z","receivedAt":"2009-04-13T16:21:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 11 Apr 2009, Ping Yin wrote:\n\n> On Sat, Apr 11, 2009 at 2:10 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > Hi,\n> >\n> > On Fri, 10 Apr 2009, Ping Yin wrote:\n> >\n> >> On Thu, Apr 9, 2009 at 10:00 AM, Ping Yin <pkufranky@gmail.com> wrote:\n> >> > On Thu, Apr 9, 2009 at 5:30 AM, Johannes Schindelin\n> >> > <johannes.schindelin@gmx.de> wrote:\n> >> >> With \"git add -e [<files>]\", Git will fire up an editor with the \n> >> >> current diff relative to the index (i.e. what you would get with \n> >> >> \"git diff [<files>]\").\n> >> >>\n> >> >> Now you can edit the patch as much as you like, including \n> >> >> adding/removing lines, editing the text, whatever.  Make sure, \n> >> >> though, that the first character of the hunk lines is still a \n> >> >> space, a plus or a minus.\n> >> >>\n> >> >> After you closed the editor, Git will adjust the line counts of \n> >> >> the hunks if necessary, thanks to the --recount option of apply, \n> >> >> and commit the patch.  Except if you deleted everything, in which \n> >> >> case nothing happens (for obvious reasons).\n> >> >>\n> >> >> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> \n> >> >> ---\n> >> >>\n> >> >>     I actually promised myself not to resend this patch, but a   \n> >> >>   certain guy who has a hat now asked for it.\n> >> >>\n> >> >\n> >> > I am that guy :-). Thanks. Sometimes \"add -e\" is more useful than \n> >> > \"add -p\" since i can see the full context when editing the patch. \n> >> > However, sometimes the ability to edit the index directly is even \n> >> > more useful. For example, if it's a big change (or rewritten), it \n> >> > is hard to edit the patch instead of the index (in diff mode with \n> >> > the worktree file side by side). I even encounter a case that i \n> >> > can't beat the patch into a shape i want when using 'add -p'  ( it \n> >> > will fail to apply)\n> >> >\n> >>\n> >> How about this?\n> >>  'add --edit=patch' to edit the patch and \"add --edit=index\" to edit the index\n> >\n> > As others have mentioned, there _is_ a reason we have a working \n> > directory. Please understand this as a \"I do not like the idea of \n> > editing the index directly at all\".\n> \n> When doing \"add --edit\" to edit the patch, do you work on the working \n> directory? I think they are just different ways to change the index?\n\nOf course I do \"git stash save --keep-index\" after staging those changes.\n\nCiao,\nDscho\n"},{"id":"111201","messageId":"fabb9a1e0904130959y20ff66a8la426f33dc0a9bf8b@mail.gmail.com","threadId":"18794","inReplyTo":"alpine.DEB.1.00.0904131817160.10279@pacific.mpi-cbg.de","subject":"Re: [PATCH] git-add: introduce --edit (to edit the diff vs. the index)","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-04-13T16:59:43Z","receivedAt":"2009-04-13T16:59:43Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, Apr 13, 2009 at 18:19, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> > Would not a much saner way be\n>\n>        $ git reset HEAD^\n>        $ git add -p\n>        $ git stash save --keep-index\n>        # test it\n>        $ git commit\n>        $ git stash apply\n>        # test again\n>        $ git commit\n\nThat's what I do already, but now imagine that at the # test it step I\nnotice that I staged too much, or need to tweak some value only in\nthis commit (e.g., change test_expect_success to test_expect_failure\nbecause this commit is the test that indicates the failure, and the\nnext one will fix it and flip from expect_failure to expect_success).\nAt the moment I have to make the change in my working directory (which\npotentially involved deleting a lot of hunks), stage that and _then_\nmake my commit. With 'git add -e' I can make the fix and happily\ncontinue.\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}