commit: add an option to reword the last commit
cover commit: add an option to reword the last commit
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before beb635ca9c ("commit: remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. These patches contain a couple of small clean ups for the commit documentation add a --reword option for commit that rewords the last commit without changing its contents.
Phillip Wood (3):
commit docs: use backquotes when quoting options
commit: reorder synopsis
commit: add an option the reword HEAD
Documentation/git-commit.txt | 30 +++++++++----- builtin/commit.c | 46 +++++++++++++++++++++- t/t7501-commit-basic-functionality.sh | 56 +++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 11 deletions(-)
base-commit: 54e85e7af1ac9e9a92888060d6811ae767fea1bc
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-736%2Fphillipwood%2Fwip%2Fcommit-reword-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-736/phillipwood/wip/commit-reword-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/736
Signature · 1 line
gitgitgadget
PATCH 1/3 commit docs: use backquotes when quoting options
From: Phillip Wood <[email protected]>
Make sure that option names are typeset in a monospace font.
--- Documentation/git-commit.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/git-commit.txt +5 -5
@@ -82,7 +82,7 @@ OPTIONS -c <commit>:: --reedit-message=<commit>:: - Like '-C', but with `-c` the editor is invoked, so that + Like `-C`, but with `-c` the editor is invoked, so that the user can further edit the commit message. --fixup=<commit>::
@@ -99,10 +99,10 @@ OPTIONS linkgit:git-rebase[1] for details. --reset-author:: - When used with -C/-c/--amend options, or when committing after a - conflicting cherry-pick, declare that the authorship of the - resulting commit now belongs to the committer. This also renews - the author timestamp. + When used with `-C`/`-c`/`--amend` options, or when committing + after a conflicting cherry-pick, declare that the authorship of + the resulting commit now belongs to the committer. This also + renews the author timestamp. --short:: When doing a dry-run, give the output in the short-format. See
Signature · 1 line
gitgitgadget
PATCH 2/3 commit: reorder synopsis
In reply to Phillip Wood via GitGitGadgetFrom: Phillip Wood <[email protected]>
Rearrange the synopsis for git commit to try and put options that are used more often nearer the beginning.
--- Documentation/git-commit.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/git-commit.txt +5 -5
@@ -8,11 +8,11 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend] - [--dry-run] [(-c | -C | --fixup | --squash) <commit>] - [-F <file> | -m <msg>] [--reset-author] [--allow-empty] - [--allow-empty-message] [--no-verify] [-e] [--author=<author>] - [--date=<date>] [--cleanup=<mode>] [--[no-]status] +'git commit' [-a | --interactive | --patch] [--amend] + [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] + [--allow-empty] [--allow-empty-message] [--no-verify] [-e] + [--reset-author] [--author=<author>] [--date=<date>] + [--cleanup=<mode>] [-v] [-u<mode>] [--dry-run] [--[no-]status] [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]] [-S[<keyid>]] [--] [<pathspec>...]
Signature · 1 line
gitgitgadget
Re: [PATCH 2/3] commit: reorder synopsis
Quoted 4 lines · Phillip Wood via GitGitGadget
From: Phillip Wood <[email protected]>
Rearrange the synopsis for
git committo try and put options that are used more often nearer the beginning.
Which option is used "more often" depends heavily on the workflow, and it is a bit unfriendly to those who are affected by this change not to list the ones you are demoting, with rationale for each, something like:
- "--dry-run" may or may not be used often, but it is orthogonal to the regular options that affect how the command behaves, and it is much less important and interesting than the other options.
Among the ones you are demoting without explanation
- "-s" is no longer even mentioned, which I do not think is a well thought out change.
- "-v" is to make the command do the same thing as it does without it, but just more loudly, so it is less interesting than the other options.
- "-u<mode>" affects what is shown in the editor to prepare the log message, which is of less importance than other options that affect the outcome of the command. When --no-status is in effect, -u<mode> would not even have any effect, so it probably makes sense to move this next to "--[no-]status".
- "--reset-author" can be used not just to take ownership of the commit from somebody else, but also be used to update the author date of your own change. It probably belongs to the same group as -c/-C/-F/-m that affects the metadata of the resulting commit and should stay at the original location in the list. If you want to change anything around this area, I'd suggest moving --date=<date> close to this "options that affect commit's metadata" group.
Quoted 25 lines
Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-commit.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)Documentation/git-commit.txt +5
-5@@ -8,11 +8,11 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend] - [--dry-run] [(-c | -C | --fixup | --squash) <commit>] - [-F <file> | -m <msg>] [--reset-author] [--allow-empty] - [--allow-empty-message] [--no-verify] [-e] [--author=<author>] - [--date=<date>] [--cleanup=<mode>] [--[no-]status] +'git commit' [-a | --interactive | --patch] [--amend] + [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] + [--allow-empty] [--allow-empty-message] [--no-verify] [-e] + [--reset-author] [--author=<author>] [--date=<date>] + [--cleanup=<mode>] [-v] [-u<mode>] [--dry-run] [--[no-]status] [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]] [-S[<keyid>]] [--] [<pathspec>...]
Re: [PATCH 2/3] commit: reorder synopsis
Quoted 11 lines · Junio C Hamano
Quoted 4 lines · Phillip Wood via GitGitGadget
From: Phillip Wood <[email protected]>
Rearrange the synopsis for
git committo try and put options that are used more often nearer the beginning.Which option is used "more often" depends heavily on the workflow, and it is a bit unfriendly to those who are affected by this change not to list the ones you are demoting, with rationale for each, something like:
I agree the changes are a bit subjective, I thought --dry-run -u<mode> and -v were probably not as important enough to justify their position on the first line and it sounds like you basically agree with that.
Quoted 8 lines
- "--dry-run" may or may not be used often, but it is orthogonal to the regular options that affect how the command behaves, and it is much less important and interesting than the other options.
Among the ones you are demoting without explanation
- "-s" is no longer even mentioned, which I do not think is a well thought out change.
That's a mistake I did not intend to remove it, thanks for spotting that
Quoted 10 lines
- "-v" is to make the command do the same thing as it does without it, but just more loudly, so it is less interesting than the other options.
- "-u<mode>" affects what is shown in the editor to prepare the log message, which is of less importance than other options that affect the outcome of the command. When --no-status is in effect, -u<mode> would not even have any effect, so it probably makes sense to move this next to "--[no-]status".
Quoted 8 lines
- "--reset-author" can be used not just to take ownership of the commit from somebody else, but also be used to update the author date of your own change. It probably belongs to the same group as -c/-C/-F/-m that affects the metadata of the resulting commit and should stay at the original location in the list. If you want to change anything around this area, I'd suggest moving --date=<date> close to this "options that affect commit's metadata" group.
I was trying to group the author/date related option together - they all affect the metadata of the resulting commit
What do you think to
-'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
- [--dry-run] [(-c | -C | --fixup | --squash) <commit>] - [-F <file> | -m <msg>] [--reset-author] [--allow-empty] - [--allow-empty-message] [--no-verify] [-e] [--author=<author>] - [--date=<date>] [--cleanup=<mode>] [--[no-]status] [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]] [-S[<keyid>]] [--] [<pathspec>...] +'git commit' [-a | --interactive | --patch] [--amend] + [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] + [--reset-author] [--author=<author>] [--date=<date>] [-s] [-e] + [--allow-empty] [--allow-empty-message] [--no-verify] + [--cleanup=<mode>] [-u<mode>] [--[no-]status] [-v] [--dry-run] [-i | -o | -p] [--pathspec-from-file=<file> [--pathspec-file-nul]]
[-S[<keyid>]] [--] [<pathspec>...]
--dry-run and -v are demoted. -u<mode> is moved next to --[no-]status as they are related. -s is restored but moved and the author/date related options are moved up to join the other options that affect the commit metadata. The downside is that --allow-empty and friends end up being moved down a line as a consequence of keeping all the commit metadata related options together.
If you are happy I'll redo the commit message based on your suggestions above
Thanks
Phillip
Quoted 27 lines
Quoted 27 lines
Signed-off-by Phillip Wood <[email protected]>--- Documentation/git-commit.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)Documentation/git-commit.txt +5
-5@@ -8,11 +8,11 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend] - [--dry-run] [(-c | -C | --fixup | --squash) <commit>] - [-F <file> | -m <msg>] [--reset-author] [--allow-empty] - [--allow-empty-message] [--no-verify] [-e] [--author=<author>] - [--date=<date>] [--cleanup=<mode>] [--[no-]status] +'git commit' [-a | --interactive | --patch] [--amend] + [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] + [--allow-empty] [--allow-empty-message] [--no-verify] [-e] + [--reset-author] [--author=<author>] [--date=<date>] + [--cleanup=<mode>] [-v] [-u<mode>] [--dry-run] [--[no-]status] [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]] [-S[<keyid>]] [--] [<pathspec>...]
Re: [PATCH 2/3] commit: reorder synopsis
Quoted 13 lines · Phillip Wood
-'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
Documentation/git-commit.txt +0
-4- [--dry-run] [(-c | -C | --fixup | --squash) <commit>] - [-F <file> | -m <msg>] [--reset-author] [--allow-empty] - [--allow-empty-message] [--no-verify] [-e] [--author=<author>] - [--date=<date>] [--cleanup=<mode>] [--[no-]status][-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]] [-S[<keyid>]] [--] [<pathspec>...]+'git commit' [-a | --interactive | --patch] [--amend]
(quoted diff) +4
-0+ [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] + [--reset-author] [--author=<author>] [--date=<date>] [-s] [-e] + [--allow-empty] [--allow-empty-message] [--no-verify] + [--cleanup=<mode>] [-u<mode>] [--[no-]status] [-v] [--dry-run][-i | -o | -p] [--pathspec-from-file=<file> [--pathspec-file-nul]]
Quoted 1 line
[-S[<keyid>]] [--] [<pathspec>...]
This seems to group them better than the original, including "--allow-empty" and its two friends that are about sanity checking.
I would actually kick "-a" out of the "--interactive | --patch" group [*1*]. Unlike the two, it is not about a different operation mode. It is closer to how paths whose contents will participate in the resulting commit are chosen, so it is much closer to the "-i" and "-o" family, I would think.
What is "git commit -p" you have next to "-i" and "-o"? I do not think it belongs there---isn't it a short form of --patch?
Thanks.
[Footnote]
*1* It was originally made that way because the "add--interactive" based operation mode was incompatible with "-a", I think. But the thing is, the interactive one is incompatible with other things like "-i" and "-o". Use of the '|' alternative notation to express things are mutually incompatible inherently does not play well with the idea of showing common things early. It would allow us to group conceptually similar things together, though.
Do we want to say "[-a | -i | -o | --interactive | --patch]" in the same [] group and show them as alternatives? That may logically make some sense, and if we were to go that route, it belongs near the end of the list, close to where we show pathspec. I dunno.
PATCH 3/3 commit: add an option the reword HEAD
In reply to Phillip Wood via GitGitGadgetFrom: Phillip Wood <[email protected]>
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before beb635ca9c ("commit:
remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. This commits adds a --reword option for commit that rewords the last commit without changing its contents.
--- Documentation/git-commit.txt | 14 ++++++- builtin/commit.c | 46 +++++++++++++++++++++- t/t7501-commit-basic-functionality.sh | 56 +++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 3 deletions(-)
Documentation/git-commit.txt +12 -2
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive | --patch] [--amend] +'git commit' [-a | --interactive | --patch] [--amend | --reword] [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--reset-author] [--author=<author>] [--date=<date>]
@@ -99,7 +99,7 @@ OPTIONS linkgit:git-rebase[1] for details. --reset-author:: - When used with `-C`/`-c`/`--amend` options, or when committing + When used with `-C`/`-c`/`--amend`/`--reword` options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp.
@@ -229,6 +229,16 @@ variable (see linkgit:git-config[1]). For example, `git commit --amend --no-edit` amends a commit without changing its commit message. +--reword:: + Reword the commit message of the tip of the current branch by + replacing it with a new commit. The commit contents will be + unchanged even if there are staged changes. This is equivalent + to specifying `--amend --only --allow-empty` with no paths. ++ +You should understand the implications of rewriting history if you +reword a commit that has already been published. (See the "RECOVERING +FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].) + --amend:: Replace the tip of the current branch by creating a new commit. The recorded tree is prepared as usual (including
builtin/commit.c +45 -1
76 lines not on this page · raw message
t/t7501-commit-basic-functionality.sh +56 -0
60 lines not on this page · raw message
Signature · 1 line
gitgitgadget
Re: [PATCH 3/3] commit: add an option the reword HEAD
builtin/commit.c static void finalize_deferred_config(struct wt_status *s) · line 1158
Quoted 13 lines · Phillip Wood via GitGitGadget
+--reword::
Documentation/git-commit.txt +4
-0+ Reword the commit message of the tip of the current branch by + replacing it with a new commit. The commit contents will be + unchanged even if there are staged changes. This is equivalent + to specifying `--amend --only --allow-empty` with no paths.builtin/commit.c +6
-0@@ -1152,6 +1153,41 @@ static void finalize_deferred_config(struct wt_status *s) +static void validate_reword_options (int argc,struct commit *current_head) +{ +if (amend) +die (_ ("cannot combine --reword with --amend" )); +if (only) +die (_ ("cannot combine --reword with --only" ));
Nit: It feels a bit odd (though not outright wrong) to disallow --reword in combination with --amend and --only after the documentation states that --reword is equivalent to using those options.
t/t7501-commit-basic-functionality.sh test_expect_success '--dry-run --short' ' · line 719
Quoted 9 lines
t/t7501-commit-basic-functionality.sh +7
-0@@ -713,4 +713,60 @@ test_expect_success '--dry-run --short' ' +test_reword_opt () { + test_expect_success C_LOCALE_OUTPUT "--reword incompatible with $1" " + echo 'fatal: cannot combine --reword with $1' >expect && + test_must_fail git commit --reword $1 2>actual && + test_cmp expect actual + " +}
These error messages are subject to localization, so you'd want to use test_i18ncmp() here, I think.
Same comment for other new tests.
Re: [PATCH 3/3] commit: add an option the reword HEAD
Hi Eric
Quoted 12 lines · Eric Sunshine
Quoted 10 lines · Phillip Wood via GitGitGadget
+--reword::
Documentation/git-commit.txt +4
-0+ Reword the commit message of the tip of the current branch by + replacing it with a new commit. The commit contents will be + unchanged even if there are staged changes. This is equivalent + to specifying `--amend --only --allow-empty` with no paths.builtin/commit.c +3
-0@@ -1152,6 +1153,41 @@ static void finalize_deferred_config(struct wt_status *s) +static void validate_reword_options (int argc,struct commit *current_head) +{ +if (amend)
Quoted 8 lines
builtin/commit.c static void finalize_deferred_config(struct wt_status *s) · line 1184
Quoted 3 lines
builtin/commit.c +3
-0+die (_ ("cannot combine --reword with --amend" )); +if (only) +die (_ ("cannot combine --reword with --only" ));Nit: It feels a bit odd (though not outright wrong) to disallow --reword in combination with --amend and --only after the documentation states that --reword is equivalent to using those options.
Yeah I decided to be quite strict, I'm in two minds about the documentation, I think it might be better to remove that line.
Quoted 13 lines
t/t7501-commit-basic-functionality.sh test_expect_success '--dry-run --short' ' · line 719
Quoted 9 lines
t/t7501-commit-basic-functionality.sh +7
-0@@ -713,4 +713,60 @@ test_expect_success '--dry-run --short' ' +test_reword_opt () { + test_expect_success C_LOCALE_OUTPUT "--reword incompatible with $1" " + echo 'fatal: cannot combine --reword with $1' >expect && + test_must_fail git commit --reword $1 2>actual && + test_cmp expect actual + " +}These error messages are subject to localization, so you'd want to use
test_i18ncmp()here, I think.
Quoted 1 line
Same comment for other new tests.
I decided to use the C_LOCALE_OUTPUT prerequisite and test_cmp rather than grep so I could check the exact output. I'm slightly suspicious of tests that just grep for an error message when that is all we should be showing. I should probably check that nothing is printed to stdout in these tests
Best Wishes
Phillip
Re: [PATCH 3/3] commit: add an option the reword HEAD
Quoted 8 lines · Phillip Wood
Quoted 4 lines · Eric Sunshine
Nit: It feels a bit odd (though not outright wrong) to disallow --reword in combination with --amend and --only after the documentation states that --reword is equivalent to using those options.
Yeah I decided to be quite strict, I'm in two minds about the documentation, I think it might be better to remove that line.
I rather like that the documentation explains the equivalency between --reword and --amend --only --allow-empty since it makes --reword less magical and provides the readers with pointers for further study.
Quoted 2 lines
I decided to use the
C_LOCALE_OUTPUTprerequisite andtest_cmprather than grep so I could check the exact output. [...]
I overlooked C_LOCALE_OUTPUT.
Re: [PATCH 3/3] commit: add an option the reword HEAD
In reply to Phillip WoodQuoted 14 lines · Phillip Wood
Quoted 5 lines
Quoted 5 lines
t/t7501-commit-basic-functionality.sh +3
-0@@ -713,4 +713,60 @@ test_expect_success '--dry-run --short' ' +test_reword_opt () { + test_expect_success C_LOCALE_OUTPUT "--reword incompatible with $1" " + echo 'fatal: cannot combine --reword with $1' >expect &&Quoted 8 lines
t/t7501-commit-basic-functionality.sh test_expect_success '--dry-run --short' ' · line 739
Quoted 4 lines
t/t7501-commit-basic-functionality.sh +4
-0+ test_must_fail git commit --reword $1 2>actual && + test_cmp expect actual + " +}These error messages are subject to localization, so you'd want to use
test_i18ncmp()here, I think.
Same comment for other new tests.
Quoted 2 lines
I decided to use the
C_LOCALE_OUTPUTprerequisite andtest_cmprather than grep so I could check the exact output.
I do not think it is a good idea. Dropping the C_LOCALE_OUTPUT prerequisite and using test_i18ncmpw would be more appropriate.
A test run without GIT_TEST_GETTEXT_POISON will do the byte-for-byte comparison like test_cmp. It is only the poison test, whose purpose is to catch commands that by mistake translated their messages, that would want to mark a test that checks end-user facing messages like this one as special with test_i18ncmp.
Quoted 2 lines
... I should probably check that nothing is printed to stdout in these tests
Perhaps, but that is not the point of "do we diagnose options thare are incompatble with --reword?" test.
Re: [PATCH 3/3] commit: add an option the reword HEAD
Hi Junio
Quoted 19 lines · Junio C Hamano
Quoted 14 lines · Phillip Wood
Quoted 5 lines
Quoted 5 lines
t/t7501-commit-basic-functionality.sh +3
-0@@ -713,4 +713,60 @@ test_expect_success '--dry-run --short' ' +test_reword_opt () { + test_expect_success C_LOCALE_OUTPUT "--reword incompatible with $1" " + echo 'fatal: cannot combine --reword with $1' >expect &&Quoted 8 lines
t/t7501-commit-basic-functionality.sh test_expect_success '--dry-run --short' ' · line 739
Quoted 4 lines
t/t7501-commit-basic-functionality.sh +4
-0+ test_must_fail git commit --reword $1 2>actual && + test_cmp expect actual + " +}These error messages are subject to localization, so you'd want to use
test_i18ncmp()here, I think.
Same comment for other new tests.Quoted 2 lines
I decided to use the
C_LOCALE_OUTPUTprerequisite andtest_cmprather than grep so I could check the exact output.
Quoted 8 lines
I do not think it is a good idea. Dropping the
C_LOCALE_OUTPUTprerequisite and usingtest_i18ncmpwwould be more appropriate.A test run without
GIT_TEST_GETTEXT_POISONwill do the byte-for-byte comparison liketest_cmp. It is only the poison test, whose purpose is to catch commands that by mistake translated their messages, that would want to mark a test that checks end-user facing messages like this one as special withtest_i18ncmp.
Thanks I wasn't aware of test_i18ncmp
Quoted 5 lines
Quoted 2 lines
... I should probably check that nothing is printed to stdout in these tests
Perhaps, but that is not the point of "do we diagnose options thare are incompatble with --reword?" test.
I think it depends if one views the test as checking "do we diagnose options there are incompatible with --reword?" or "what do we show the user when there are options that are incompatible with --reword". For the former we just want to check that the correct error message is printed, for the latter we want to check that only what we expect to be printed is actually printed.
Best Wishes
Phillip
Re: [PATCH 3/3] commit: add an option the reword HEAD
Quoted 7 lines · Phillip Wood
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
+test_reword_opt () {
...... I should probably check that nothing is printed to stdout in these tests
Perhaps, but that is not the point of "do we diagnose options thare are incompatble with --reword?" test.
Quoted 6 lines
I think it depends if one views the test as checking "do we diagnose options there are incompatible with --reword?" or "what do we show the user when there are options that are incompatible with --reword". For the former we just want to check that the correct error message is printed, for the latter we want to check that only what we expect to be printed is actually printed.
I dunno. It is plausible that we will further give some advices (not directly related to --reword option being incompatible with other options) and output may evolve. I do not think we want to be updating each and every test that expects exact output.
In other words, the answer to "what do we show when --reword and another incompatible option are given?" is "we want to point it out that --reword and --amend are not to be used together" and not "and we should not ever say anything else".
Just like back when we started making sure everybody sets user.name configuration variable (and the way to do so was to give warnings and advices at strategic places), output can be added to commands where authors if each individual feature would not expect. I would want to see our tests prepared for such an occasion. We cannot be perfectly prepared, of course, but keeping the expectation focused enough to check what really matters for the objective at hand would help.
Thanks.
Re: [PATCH 3/3] commit: add an option the reword HEAD
In reply to Phillip Wood via GitGitGadgetQuoted 1 line · Phillip Wood via GitGitGadget
If one notices a typo in the last commit ...
In the title "commit: add an option the reword HEAD", I would suggest s/the/to/ :-)
Re: [PATCH 3/3] commit: add an option the reword HEAD
Quoted 7 lines · Christian Couder
Quoted 1 line · Phillip Wood via GitGitGadget
If one notices a typo in the last commit ...
In the title "commit: add an option the reword HEAD", I would suggest s/the/to/ :-)
Well spotted Christian, Thanks
Phillip
Re: [PATCH 3/3] commit: add an option the reword HEAD
In reply to Phillip Wood via GitGitGadgetHi Phillip,
Quoted 13 lines · Phillip Wood via GitGitGadget
From: Phillip Wood <[email protected]>
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before
beb635ca9c("commit:
remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. This commits adds a --reword option for commit that rewords the last commit without changing its contents.
I would like to explain the idea I tried to get across when I proposed to implement support for reword! (and --reword) because I feel that it will change the design of this patch in a rather big way.
First of all, let me explain the scenario in which I long for the --reword option: I maintain several patch thickets, the most obvious one being Git for Windows' patch thicket that is merge-rebased [*1*] onto every new Git version.
At times, I need to adjust a commit message in that patch thicket. It would be quite wasteful to perform a full merge-rebase, therefore I typically call git commit --squash <commit> -c <commit>, copy the oneline, paste it after the squash! line (surrounded by empty lines), and then reword the commit message. When the next Git version comes out, I do a merging-rebase, and when the editor pops up because of that squash! oneline, I remove the now-obsolete version(s) of the commit message.
Obviously, I have to be careful to either also pass --only (which I somehow managed to learn about only today) or I have to make sure that I have no staged changes. In practice, I actually specify a bogus path, which has the same effect as --only.
What I would actually rather have is the --reword option: git commit --reword <commit>. In my mind, this would _add_ a new, "empty" commit, letting me edit the commit message of the specified commit, and using that as commit message, prefixed with the line reword! <oneline>.
This, in turn, would need to be accompanied by support in the interactive rebase, to perform the desired reword (which is admittedly quite a bit different from what the way the todo command reword works).
With that in mind, I would like to caution against the design of your current patch, because it would slam the door shut on the way I would like --reword to work.
Ciao,
Dscho
Footnote *1*: In Git for Windows, I want to not only rebase the patches (so that they are as ready to be submitted to the Git mailing list as they can be) but I also want the commit history to fast-forward. The strategy I settled on is the "merging rebase": it is a rebase that starts with a fake merge of the previous commit history, i.e. merging it in using -s ours so that only the commit history comes in, but not the changes. This allows contributors to pull without problems, but also provides the benefits of having a rebased version of the patches. The price is a rather big commit history on top of Git's main branch, as Git for Windows' main branch contains not only the newest iteration of its patches, but _all_ iterations (at least since the first merging-rebase).
Re: [PATCH 3/3] commit: add an option the reword HEAD
Hi Dscho
Quoted 45 lines · Johannes Schindelin
Hi Phillip,
Quoted 13 lines · Phillip Wood via GitGitGadget
From: Phillip Wood <[email protected]>
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before
beb635ca9c("commit:
remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. This commits adds a --reword option for commit that rewords the last commit without changing its contents.I would like to explain the idea I tried to get across when I proposed to implement support for
reword!(and--reword) because I feel that it will change the design of this patch in a rather big way.First of all, let me explain the scenario in which I long for the
--rewordoption: I maintain several patch thickets, the most obvious one being Git for Windows' patch thicket that is merge-rebased [*1*] onto every new Git version.At times, I need to adjust a commit message in that patch thicket. It would be quite wasteful to perform a full merge-rebase, therefore I typically call
git commit --squash <commit> -c <commit>, copy the oneline, paste it after thesquash!line (surrounded by empty lines), and then reword the commit message. When the next Git version comes out, I do a merging-rebase, and when the editor pops up because of thatsquash!oneline, I remove the now-obsolete version(s) of the commit message.Obviously, I have to be careful to either also pass
--only(which I somehow managed to learn about only today) or I have to make sure that I have no staged changes. In practice, I actually specify a bogus path, which has the same effect as--only.What I would actually rather have is the
--rewordoption:git commit --reword <commit>. In my mind, this would _add_ a new, "empty" commit, letting me edit the commit message of the specified commit, and using that as commit message, prefixed with the linereword! <oneline>.
Quoted 7 lines
This, in turn, would need to be accompanied by support in the interactive rebase, to perform the desired reword (which is admittedly quite a bit different from what the way the todo command
rewordworks).With that in mind, I would like to caution against the design of your current patch, because it would slam the door shut on the way I would like
--rewordto work.
I'm keen to have an easy way to reword HEAD and a way to implement your reword! idea.
I posted a comment on your gitgitgadget issue about reword! and drop![1] pointing to some patches[2] that implement the reword! idea as amend!. I think we want to be able to fixup a commit and reword it at the same time which is way I chose the name amend! rather than reword! The implementation currently changes git commit --amend to take an optional commit which isn't ideal. I wonder if calling it revise! would be better then we could have git commit --reword to reword HEAD and git commit --revise <commit> to create a commit that will reword and fixup <commit> when the user runs git rebase -i --autostash. fold! is another possibility.
I don't think this patch series stops us implementing something for rebase but it would mean we couldn't use the name reword! unless we allow git commit --reword to take an optional commit which I'm not that keen on.
What do you think to an alternative name?
Best Wishes
Phillip
[1] https://github.com/gitgitgadget/git/issues/259
[2] https://github.com/phillipwood/git/commits/wip/rebase-amend
Quoted 15 lines
Ciao,
DschoFootnote *1*: In Git for Windows, I want to not only rebase the patches (so that they are as ready to be submitted to the Git mailing list as they can be) but I also want the commit history to fast-forward. The strategy I settled on is the "merging rebase": it is a rebase that starts with a fake merge of the previous commit history, i.e. merging it in using
-s oursso that only the commit history comes in, but not the changes. This allows contributors to pull without problems, but also provides the benefits of having a rebased version of the patches. The price is a rather big commit history on top of Git's main branch, as Git for Windows' main branch contains not only the newest iteration of its patches, but _all_ iterations (at least since the first merging-rebase).
Re: [PATCH 3/3] commit: add an option the reword HEAD
Hi Phillip,
Quoted 66 lines · Phillip Wood
Quoted 44 lines · Johannes Schindelin
Quoted 13 lines · Phillip Wood via GitGitGadget
From: Phillip Wood <[email protected]>
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before
beb635ca9c("commit:
remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. This commits adds a --reword option for commit that rewords the last commit without changing its contents.I would like to explain the idea I tried to get across when I proposed to implement support for
reword!(and--reword) because I feel that it will change the design of this patch in a rather big way.First of all, let me explain the scenario in which I long for the
--rewordoption: I maintain several patch thickets, the most obvious one being Git for Windows' patch thicket that is merge-rebased [*1*] onto every new Git version.At times, I need to adjust a commit message in that patch thicket. It would be quite wasteful to perform a full merge-rebase, therefore I typically call
git commit --squash <commit> -c <commit>, copy the oneline, paste it after thesquash!line (surrounded by empty lines), and then reword the commit message. When the next Git version comes out, I do a merging-rebase, and when the editor pops up because of thatsquash!oneline, I remove the now-obsolete version(s) of the commit message.Obviously, I have to be careful to either also pass
--only(which I somehow managed to learn about only today) or I have to make sure that I have no staged changes. In practice, I actually specify a bogus path, which has the same effect as--only.What I would actually rather have is the
--rewordoption:git commit --reword <commit>. In my mind, this would _add_ a new, "empty" commit, letting me edit the commit message of the specified commit, and using that as commit message, prefixed with the linereword! <oneline>.Quoted 7 lines
This, in turn, would need to be accompanied by support in the interactive rebase, to perform the desired reword (which is admittedly quite a bit different from what the way the todo command
rewordworks).With that in mind, I would like to caution against the design of your current patch, because it would slam the door shut on the way I would like
--rewordto work.I'm keen to have an easy way to reword HEAD and a way to implement your reword! idea.
I posted a comment on your gitgitgadget issue about reword! and drop![1] pointing to some patches[2] that implement the reword! idea as amend!. I think we want to be able to fixup a commit and reword it at the same time which is way I chose the name amend! rather than reword! The implementation currently changes
git commit --amendto take an optional commit which isn't ideal. I wonder if calling it revise! would be better then we could havegit commit --rewordto reword HEAD andgit commit --revise <commit>to create a commit that will reword and fixup <commit> when the user runsgit rebase -i --autostash. fold! is another possibility.
Quoted 5 lines
I don't think this patch series stops us implementing something for rebase but it would mean we couldn't use the name reword! unless we allow
git commit --rewordto take an optional commit which I'm not that keen on.What do you think to an alternative name?
I am really worried that the proliferation of confusingly similar options will increase Git's reputation for being awfully hard to use.
Ciao,
Dscho
Re: [PATCH 3/3] commit: add an option the reword HEAD
Hi Dscho
Quoted 70 lines · Johannes Schindelin
Hi Phillip,
Quoted 66 lines · Phillip Wood
Quoted 44 lines · Johannes Schindelin
Quoted 13 lines · Phillip Wood via GitGitGadget
From: Phillip Wood <[email protected]>
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before
beb635ca9c("commit:
remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. This commits adds a --reword option for commit that rewords the last commit without changing its contents.I would like to explain the idea I tried to get across when I proposed to implement support for
reword!(and--reword) because I feel that it will change the design of this patch in a rather big way.First of all, let me explain the scenario in which I long for the
--rewordoption: I maintain several patch thickets, the most obvious one being Git for Windows' patch thicket that is merge-rebased [*1*] onto every new Git version.At times, I need to adjust a commit message in that patch thicket. It would be quite wasteful to perform a full merge-rebase, therefore I typically call
git commit --squash <commit> -c <commit>, copy the oneline, paste it after thesquash!line (surrounded by empty lines), and then reword the commit message. When the next Git version comes out, I do a merging-rebase, and when the editor pops up because of thatsquash!oneline, I remove the now-obsolete version(s) of the commit message.Obviously, I have to be careful to either also pass
--only(which I somehow managed to learn about only today) or I have to make sure that I have no staged changes. In practice, I actually specify a bogus path, which has the same effect as--only.What I would actually rather have is the
--rewordoption:git commit --reword <commit>. In my mind, this would _add_ a new, "empty" commit, letting me edit the commit message of the specified commit, and using that as commit message, prefixed with the linereword! <oneline>.Quoted 7 lines
This, in turn, would need to be accompanied by support in the interactive rebase, to perform the desired reword (which is admittedly quite a bit different from what the way the todo command
rewordworks).With that in mind, I would like to caution against the design of your current patch, because it would slam the door shut on the way I would like
--rewordto work.I'm keen to have an easy way to reword HEAD and a way to implement your reword! idea.
I posted a comment on your gitgitgadget issue about reword! and drop![1] pointing to some patches[2] that implement the reword! idea as amend!. I think we want to be able to fixup a commit and reword it at the same time which is way I chose the name amend! rather than reword! The implementation currently changes
git commit --amendto take an optional commit which isn't ideal. I wonder if calling it revise! would be better then we could havegit commit --rewordto reword HEAD andgit commit --revise <commit>to create a commit that will reword and fixup <commit> when the user runsgit rebase -i --autostash. fold! is another possibility.
Quoted 8 lines
Quoted 5 lines
I don't think this patch series stops us implementing something for rebase but it would mean we couldn't use the name reword! unless we allow
git commit --rewordto take an optional commit which I'm not that keen on.What do you think to an alternative name?
I am really worried that the proliferation of confusingly similar options will increase Git's reputation for being awfully hard to use.
That is certainly a consideration, but not having a way to easily reword the last commit without changing its contents does not to improve Git's user friendliness. If you only just discovered using --only for rewording it's a fair bet a lot of regular users are unaware of it.
The reason I'm not keen on having --amend or --reword take an optional commit is that I think it is confusing as it means sometimes that option creates a new commit and sometimes it modifies the last commit furthermore passing --reword=HEAD would not reword HEAD but creates a reword! commit.
Rewording the last commit and creating a reword! commit are two different operations so I'm not sure having different options for them is that bad. To me the real confusion is that we end up with 3 options that create different flavors of fixup commits. It would be much nicer if there was a single fixup type that reworded the message as well as fixing up the contents and users just passed --no-edit to avoid changing the message. I'd really like to somehow change the semantics of git commit --fixup/--squash and the rebase fixup/squash commands to actually reword the commit. I guess that would mean an opt-in config setting which isn't ideal.
As an aside I'd like to see a new rewrite command that wraps the functionality of rebase -i so the user does not have to deal with fixups and editing a todo list. git rewrite amend <commit> would be equivalent to starting a rebase and marking <commit> as edit, the user can then make their changes and run git rewrite continue which would finish the rebase or git rewrite amend <another-commit> which would either alter the todo list to mark <another-commit> as edit or create new entries to rewind the rebase if <another-commit> is not in the todo list and then run git rebase --continue. Additionally there would be reword and drop commands and support for blame so that the user can do all this from an editor which would run git rewrite amend -L <current-line> <current-file> to amend the commit that introduced the current line. I've got a nasty scheme prototype of this and I've found it really useful. For an individual developer developing a patch series it is much more convenient to just edit the history directly rather than creating fixup! commits (which often seem to have conflicts when they are applied). It would not address your use where you don't want to be rebasing all the time though.
Best Wishes
Phillip
Quoted 3 lines
Ciao,
Dscho
Re: [PATCH 3/3] commit: add an option the reword HEAD
Quoted 8 lines · Phillip Wood
Quoted 8 lines
Quoted 5 lines
I don't think this patch series stops us implementing something for rebase but it would mean we couldn't use the name reword! unless we allow
git commit --rewordto take an optional commit which I'm not that keen on.What do you think to an alternative name?
I am really worried that the proliferation of confusingly similar options
will increase Git's reputation for being awfully hard to use.
Quoted 6 lines
...
The reason I'm not keen on having --amend or --reword take an optional commit is that I think it is confusing as it means sometimes that option creates a new commit and sometimes it modifies the last commit furthermore passing --reword=HEAD would not reword HEAD but creates a reword! commit.
Adding just another subjective view to the two already presented, but I think --reword, as presented by Phillip, sits better next to the existing --amend.
I wonder if we can extend the existing "--fixup <commit>" (and perhaps "--squash <commit>") to make them work better with the workflow Dscho envisions? Explicit presence of the "-e" option might be a way to tell the command to behave differently from the current "--fixup" and to leave a mark that is different from 'fixup!" in the resulting commit to affect the later "rebase" step as well, for example.
Quoted 7 lines · Phillip Wood via GitGitGadget
If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before
beb635ca9c("commit: remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it).
;-)
"git commit --only --amend" could already be read as an instruction that "I am only amending without changing anything else", but I agree that the new --reword verb is a good addition.
The only comment I had on the series was that the mutual-exclusivity logic looked a bit fragile against feature evolution of the command, but I have no concrete suggestion to make it more robust against time.