Query on git commit amend
Hello,
Suppose i want to add few new changes to my last commit (HEAD). The way i do it is
$ git add all_changed_files $ git commit --amend
OR
$ git commit --amend -a
With both these ways, i get a screen to edit the message too.
I want to know if there is a way to skip this screen.
i.e.
$ git commit --amend -a -some_other_option
which simply adds new changes to existing commit, without asking to change message.
If there is no such way, then can we add a patch for this, if it looks a valid case.
Signature · 1 line
viresh
Quoted 12 lines · On Tue, 6 Dec 2011 13:53:00 +0530 Viresh Kumar <[email protected]> wrote:
Suppose i want to add few new changes to my last commit (HEAD). The way i do it is
$ git add all_changed_files $ git commit --amendOR
$ git commit --amend -aWith both these ways, i get a screen to edit the message too.
I want to know if there is a way to skip this screen.
Quoted 8 lines
i.e.
$ git commit --amend -a -some_other_optionwhich simply adds new changes to existing commit, without asking to change message.
If there is no such way, then can we add a patch for this, if it looks a valid case.
git commit --amend -C HEAD
Am 06.12.2011 10:01 schrieb Konstantin Khomoutov:
Quoted 18 lines
Quoted 15 lines · On Tue, 6 Dec 2011 13:53:00 +0530 Viresh Kumar <[email protected]> wrote:
Suppose i want to add few new changes to my last commit (HEAD). The way i do it is
$ git add all_changed_files $ git commit --amendOR
$ git commit --amend -aWith both these ways, i get a screen to edit the message too.
I want to know if there is a way to skip this screen.
i.e.
$ git commit --amend -a -some_other_option
Quoted 6 lines
Quoted 5 lines
which simply adds new changes to existing commit, without asking to change message.
If there is no such way, then can we add a patch for this, if it looks a valid case.
git commit --amend -C HEAD
$ git commit --amend -C HEAD
works fine but will keep the authorship (name _and_ date). To change the date to the current timestamp, use
$ git commit --amend -C HEAD --reset-author
Note that this will also change the author's name to yours, so it depends on your case. The commiter's name and timestamp are always updated to "you/now", independently of that option. To change only the author's date, use --date=<date>.
Cheers,
Dirk
Am 12/6/2011 9:23, schrieb Viresh Kumar:
Quoted 13 lines
Hello,
Suppose i want to add few new changes to my last commit (HEAD). The way i do it is
$ git add all_changed_files $ git commit --amendOR
$ git commit --amend -aWith both these ways, i get a screen to edit the message too.
Quoted 7 lines
I want to know if there is a way to skip this screen.
i.e.
$ git commit --amend -a -some_other_optionwhich simply adds new changes to existing commit, without asking to change message.
$ git commit --amend -a -C HEAD
But let's count keystrokes (after -a):
<BLANK>-<SHIFT>C<BLANK>HEAD<ENTER>
10 keystrokes (more if you release SHIFT before D)
But if vi pops up you have:
<ENTER><SHIFT>ZZ
4 keystrokes
Where is the advantage of the option?
-- Hannes
Quoted 8 lines · Johannes Sixt
Am 12/6/2011 9:23, schrieb Viresh Kumar:
$ git commit --amend -a -C HEADBut let's count keystrokes (after -a):
<BLANK>-<SHIFT>C<BLANK>HEAD<ENTER>
10 keystrokes (more if you release SHIFT before D)
Quoted 7 lines
But if vi pops up you have:
<ENTER><SHIFT>ZZ
4 keystrokesWhere is the advantage of the option?
Thanks guys.
@Johannes: You are right but, i will make an alias for the entire command. So keystrokes are same for me. :)
Signature · 1 line
viresh
Quoted 14 lines · Viresh Kumar
Quoted 13 lines · Johannes Sixt
Am 12/6/2011 9:23, schrieb Viresh Kumar:
$ git commit --amend -a -C HEADBut let's count keystrokes (after -a):
<BLANK>-<SHIFT>C<BLANK>HEAD<ENTER>
10 keystrokes (more if you release SHIFT before D)But if vi pops up you have:
<ENTER><SHIFT>ZZ
4 keystrokes
Quoted 8 lines
Quoted 2 lines
Where is the advantage of the option?
Thanks guys.
@Johannes: You are right but, i will make an alias for the entire command. So keystrokes are same for me. :)
There is one more benefit, we don't have to wait for git. We can simply switch to some other window and work. And can write further command on the same window, in the time git processes commit --amend.
Signature · 1 line
viresh
Quoted 14 lines · Viresh Kumar
Hello,
Suppose i want to add few new changes to my last commit (HEAD). The way i do it is
$ git add all_changed_files $ git commit --amendOR
$ git commit --amend -aWith both these ways, i get a screen to edit the message too.
I want to know if there is a way to skip this screen.
Quoted 8 lines
i.e.
$ git commit --amend -a -some_other_optionwhich simply adds new changes to existing commit, without asking to change message.
If there is no such way, then can we add a patch for this, if it looks a valid case.
I've found
$ GIT_EDITOR=cat git commit --amend
useful.
The benefit of this technique is that it even works for git-rebase -i.
In my typical git usage, I do a lot of git-commit --fixup's. After reaching a level of stability, I change the history with:
GIT_EDITOR=cat git rebase -i --autosquash
and my history is adjusted without requiring manual intervention.
Signature · 4 lines
Cheers ~vijay Gnus should be more complicated.
Quoted 7 lines · Vijay Lakshminarayanan
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
The benefit of this technique is that it even works for git-rebase -i.
I sometimes do a similar thing, but I don't use "cat". That will dump all of the log message (including the generated template) to stdout (i.e., the terminal), which is quite noisy. Instead, I use:
GIT_EDITOR=true git commit --amend
which silently leaves the file untouched.
-Peff
Quoted 10 lines · Jeff King
Quoted 7 lines · Vijay Lakshminarayanan
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
The benefit of this technique is that it even works for git-rebase -i.
Quoted 7 lines
I sometimes do a similar thing, but I don't use "cat". That will dump all of the log message (including the generated template) to stdout (i.e., the terminal), which is quite noisy. Instead, I use:
GIT_EDITOR=true git commit --amendwhich silently leaves the file untouched.
Thanks Peff. I didn't know about true. I will use it when rebasing. cat's noisiness is useful as a review of the output.
Quoted 1 line
-Peff
Signature · 4 lines
Cheers ~vijay Gnus should be more complicated.
Quoted 5 lines · Vijay Lakshminarayanan
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
Are you sure it is a cat?
I almost always use
$ EDITOR=: git commit --amend
when rewriting the contents without updating the message, but I think we should allow people to say:
$ git commit --amend --no-edit
which is accepted from the command line but is not honoured.
Quoted 10 lines · Junio C Hamano
I almost always use
$ EDITOR=: git commit --amendwhen rewriting the contents without updating the message, but I think we should allow people to say:
$ git commit --amend --no-editwhich is accepted from the command line but is not honoured.
And this should fix it (only lightly tested).
-- >8 --
Subject: [PATCH] commit: honor --no-edit
After making fixes to the contents to be committed, it is not unusual to update the current commit without rewording the message. Idioms to do tell "commit --amend" that we do not need an editor have been:
$ EDITOR=: git commit --amend
$ git commit --amend -C HEADbut that was only because a more natural
$ git commit --amend --no-edit
did not honour "--no-edit" option.
--- builtin/commit.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
builtin/commit.c +5 -4
@@ -81,7 +81,8 @@ static const char *template_file;static const char *author_message, *author_message_buffer;static char *edit_message, *use_message;static char *fixup_message, *squash_message; -static int all, edit_flag, also, interactive, patch_interactive, only, amend, signoff; +static int all, also, interactive, patch_interactive, only, amend, signoff; +static int edit_flag =-1 ;/* unspecified */ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;static int no_post_rewrite, allow_empty_message;static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
@@ -141,7 +142,7 @@ static struct option builtin_commit_options[] = {OPT_BOOLEAN (0 ,"reset-author" , &renew_authorship,"the commit is authored by me now (used with -C-c/--amend)" ),OPT_BOOLEAN ('s' ,"signoff" , &signoff,"add Signed-off-by:" ),OPT_FILENAME ('t' ,"template" , &template_file,"use specified template file" ), -OPT_BOOLEAN ('e' ,"edit" , &edit_flag,"force edit of commit" ), +OPT_BOOL ('e' ,"edit" , &edit_flag,"force edit of commit" ),OPT_STRING (0 ,"cleanup" , &cleanup_arg,"default" ,"how to strip spaces and #comments from message" ), OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),/* end commit message options */
@@ -1020,8 +1021,8 @@ static int parse_and_validate_options(int argc, const char *argv[],if (logfile || message.len || use_message || fixup_message) use_editor =0 ; -if (edit_flag) - use_editor =1 ; +if (0 <= edit_flag) + use_editor = edit_flag;if (!use_editor)setenv ("GIT_EDITOR" ,":" ,1 );
Signature · 1 line
1.7.8.157.g03e55
[PATCH/RFC 0/4] Re: commit: honor --no-edit
Quoted 9 lines · Junio C Hamano
And this should fix it (only lightly tested).
-- >8 --
Subject: [PATCH] commit: honor --no-editAfter making fixes to the contents to be committed, it is not unusual to update the current commit without rewording the message. Idioms to do tell "commit --amend" that we do not need an editor have been:
Quoted 8 lines
$ EDITOR=: git commit --amend $ git commit --amend -C HEADbut that was only because a more natural
$ git commit --amend --no-editdid not honour "--no-edit" option.
I like it.
Here are a couple of tests. The three patches before are just to make it less frightening to add to the relevant test script.
Jonathan Nieder (4):
test: add missing "&&" after echo command
test: remove a test of porcelain that hardcodes commit ids t7501 (commit): modernize style
test: commit --amend should honor --no-edit
t/t7501-commit.sh | 335 ++++++++++++++++++++++++++++------------------------- 1 files changed, 175 insertions(+), 160 deletions(-)
PATCH 1/4 test: add missing "&&" after echo command
This test wants to modify a file and commit the change, but because of a missing separator between commands it is parsed as a single "echo" command.
--- t/t7501-commit.sh | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
t/t7501-commit.sh +7 -6
@@ -60,7 +60,7 @@ test_expect_success \ test_expect_success \ "next commit" \ - "echo 'bongo bongo bongo' >file \ + "echo 'bongo bongo bongo' >file && \ git commit -m next -a" test_expect_success \
@@ -172,11 +172,12 @@ test_expect_success \ # easier to isolate bugs. cat >expected <<\EOF -72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca -9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2 -3536bbb352c3a1ef9a420f5b4242d48578b92aa7 -d381ac431806e53f3dd7ac2f1ae0534f36d738b9 -4fd44095ad6334f3ef72e4c5ec8ddf108174b54a +285fcf7ec0d61b14249dfdb4c1e1fe03eaf15ee0 +0b8148b9afce917b87d71199b900466dc8ea8b6e +43fb8826314939ce79a856face7953557fdca3d1 +eaa04bc3ae0f0b003f7f1d86bf869ec5d73eaf3e +ee1963b250ee0f02a3fe37be0e4a02bb5af6a1ad +b49f306003c627361a0304d151a6b4c8b26af6a1 402702b49136e7587daa9280e91e4bb7cb2179f7 EOF
Signature · 1 line
1.7.8.rc3
PATCH 2/4 test: remove a porcelain test that hard-codes commit names
In reply to Jonathan NiederThe rev-list output in this test depends on the details of test_tick's dummy dates and the choice of hash function. Worse, it depends on the order and nature of commits made in the earlier tests, so adding new tests or rearranging existing ones breaks it.
It would be nice to check that "git commit" and commit-tree name objects consistently and that commit objects' text is as documented, but this particular test checks everything at once and hence is not a robust test for that. Remove it.
---
Hence the odd hunk in the previous patch.
Maybe this doesn't belong in this series, but it's the kind of thing that drives me batty when writing new tests.
t/t7501-commit.sh | 20 -------------------- 1 files changed, 0 insertions(+), 20 deletions(-)
t/t7501-commit.sh +0 -20
@@ -144,10 +144,6 @@ test_expect_success PERL \ git diff >diff2 && test_cmp diff1 diff2" -test_expect_success \ - "showing committed revisions" \ - "git rev-list HEAD >current" - cat >editor <<\EOF #!/bin/sh sed -e "s/good/bad/g" < "$1" > "$1-"
@@ -168,22 +164,6 @@ test_expect_success \ echo "Another good message." | EDITOR=./editor git commit -a -F - && git show -s --pretty=format:"%s" | grep -q good ' -# We could just check the head sha1, but checking each commit makes it -# easier to isolate bugs. - -cat >expected <<\EOF -285fcf7ec0d61b14249dfdb4c1e1fe03eaf15ee0 -0b8148b9afce917b87d71199b900466dc8ea8b6e -43fb8826314939ce79a856face7953557fdca3d1 -eaa04bc3ae0f0b003f7f1d86bf869ec5d73eaf3e -ee1963b250ee0f02a3fe37be0e4a02bb5af6a1ad -b49f306003c627361a0304d151a6b4c8b26af6a1 -402702b49136e7587daa9280e91e4bb7cb2179f7 -EOF - -test_expect_success \ - 'validate git rev-list output.' \ - 'test_cmp expected current' test_expect_success 'partial commit that involves removal (1)' '
Signature · 1 line
1.7.8.rc3
PATCH 3/4 t7501 (commit): modernize style
In reply to Jonathan NiederPut the opening quote starting each test on the same line as the test_expect_* invocation. While at it:
- guard commands that prepare test input for individual tests in the same test_expect_success, so their scope is clearer and errors at that stage can be caught;
- use the compare_diff_patch helper function when comparing patches;
- use single-quotes in preference to double-quotes and <<\EOF in preference to <<EOF, to save readers the trouble of looking for variable interpolations;
- lift the setting of the $author variable used throughout the test script to the top of the test script;
- include "setup" in the titles of test assertions that prepare for later ones to make it more obvious which tests can be skipped;
- use test_must_fail instead of "if ...; then:; else false; fi", for clarity and to catch segfaults when they happen;
- break up some pipelines into separate commands that read and write to ordinary files, and test the exit status at each stage;
- chain commands with &&. Breaks in a test assertion's && chain can potentially hide failures from earlier commands in the chain;
- combine two initial tests that do not make as much sense alone.
---
Miscellaneous cleanups.
t/t7501-commit.sh | 278 ++++++++++++++++++++++++++--------------------------- 1 files changed, 136 insertions(+), 142 deletions(-)
t/t7501-commit.sh +136 -142
@@ -8,39 +8,39 @@ test_description='git commit' . ./test-lib.sh +. "$TEST_DIRECTORY/diff-lib.sh" + +author='The Real Author <[email protected]>' test_tick -test_expect_success \ - "initial status" \ - "echo 'bongo bongo' >file && - git add file" - -test_expect_success "Constructing initial commit" ' +test_expect_success 'initial status' ' + echo bongo bongo >file && + git add file && git status >actual && test_i18ngrep "Initial commit" actual ' -test_expect_success \ - "fail initial amend" \ - "test_must_fail git commit --amend" +test_expect_success 'fail initial amend' ' + test_must_fail git commit --amend +' -test_expect_success \ - "initial commit" \ - "git commit -m initial" +test_expect_success 'setup: initial commit' ' + git commit -m initial +' -test_expect_success \ - "invalid options 1" \ - "test_must_fail git commit -m foo -m bar -F file" +test_expect_success '-m and -F do not mix' ' + test_must_fail git commit -m foo -m bar -F file +' -test_expect_success \ - "invalid options 2" \ - "test_must_fail git commit -C HEAD -m illegal" +test_expect_success '-m and -C do not mix' ' + test_must_fail git commit -C HEAD -m illegal +' -test_expect_success \ - "using paths with -a" \ - "echo King of the bongo >file && - test_must_fail git commit -m foo -a file" +test_expect_success 'paths and -a do not mix' ' + echo King of the bongo >file && + test_must_fail git commit -m foo -a file +' test_expect_success PERL 'can use paths with --interactive' ' echo bong-o-bong >file &&
@@ -50,120 +50,123 @@ test_expect_success PERL 'can use paths with --interactive' ' git reset --hard HEAD^ ' -test_expect_success \ - "using invalid commit with -C" \ - "test_must_fail git commit -C bogus" - -test_expect_success \ - "testing nothing to commit" \ - "test_must_fail git commit -m initial" - -test_expect_success \ - "next commit" \ - "echo 'bongo bongo bongo' >file && \ - git commit -m next -a" - -test_expect_success \ - "commit message from non-existing file" \ - "echo 'more bongo: bongo bongo bongo bongo' >file && \ - test_must_fail git commit -F gah -a" - -# Empty except stray tabs and spaces on a few lines. -sed -e 's/@$//' >msg <<EOF - @ - - @ -Signed-off-by: hula -EOF -test_expect_success \ - "empty commit message" \ - "test_must_fail git commit -F msg -a" - -test_expect_success \ - "commit message from file" \ - "echo 'this is the commit message, coming from a file' >msg && \ - git commit -F msg -a" - -cat >editor <<\EOF -#!/bin/sh -sed -e "s/a file/an amend commit/g" < "$1" > "$1-" -mv "$1-" "$1" -EOF -chmod 755 editor - -test_expect_success \ - "amend commit" \ - "EDITOR=./editor git commit --amend" - -test_expect_success \ - "passing -m and -F" \ - "echo 'enough with the bongos' >file && \ - test_must_fail git commit -F msg -m amending ." - -test_expect_success \ - "using message from other commit" \ - "git commit -C HEAD^ ." - -cat >editor <<\EOF -#!/bin/sh -sed -e "s/amend/older/g" < "$1" > "$1-" -mv "$1-" "$1" -EOF -chmod 755 editor - -test_expect_success \ - "editing message from other commit" \ - "echo 'hula hula' >file && \ - EDITOR=./editor git commit -c HEAD^ -a" - -test_expect_success \ - "message from stdin" \ - "echo 'silly new contents' >file && \ - echo commit message from stdin | git commit -F - -a" - -test_expect_success \ - "overriding author from command line" \ - "echo 'gak' >file && \ - git commit -m 'author' --author 'Rubber Duck <[email protected]>' -a >output 2>&1" - -test_expect_success \ - "commit --author output mentions author" \ - "grep Rubber.Duck output" - -test_expect_success PERL \ - "interactive add" \ - "echo 7 | git commit --interactive | grep 'What now'" - -test_expect_success PERL \ - "commit --interactive doesn't change index if editor aborts" \ - "echo zoo >file && +test_expect_success 'using invalid commit with -C' ' + test_must_fail git commit -C bogus +' + +test_expect_success 'nothing to commit' ' + test_must_fail git commit -m initial +' + +test_expect_success 'setup: non-initial commit' ' + echo bongo bongo bongo >file && + git commit -m next -a +' + +test_expect_success 'commit message from non-existing file' ' + echo more bongo: bongo bongo bongo bongo >file && + test_must_fail git commit -F gah -a +' + +test_expect_success 'empty commit message' ' + # Empty except stray tabs and spaces on a few lines. + sed -e "s/@//g" >msg <<-\EOF && + @ @ + @@ + @ @ + @Signed-off-by: hula@ + EOF + test_must_fail git commit -F msg -a +' + +test_expect_success 'setup: commit message from file' ' + echo this is the commit message, coming from a file >msg && + git commit -F msg -a +' + +test_expect_success 'amend commit' ' + cat >editor <<-\EOF && + #!/bin/sh + sed -e "s/a file/an amend commit/g" < "$1" > "$1-" + mv "$1-" "$1" + EOF + chmod 755 editor && + EDITOR=./editor git commit --amend +' + +test_expect_success '-m and -F do not mix' ' + echo enough with the bongos >file && + test_must_fail git commit -F msg -m amending . +' + +test_expect_success 'using message from other commit' ' + git commit -C HEAD^ . +' + +test_expect_success 'editing message from other commit' ' + cat >editor <<-\EOF && + #!/bin/sh + sed -e "s/amend/older/g" < "$1" > "$1-" + mv "$1-" "$1" + EOF + chmod 755 editor && + echo hula hula >file && + EDITOR=./editor git commit -c HEAD^ -a +' + +test_expect_success 'message from stdin' ' + echo silly new contents >file && + echo commit message from stdin | + git commit -F - -a +' + +test_expect_success 'overriding author from command line' ' + echo gak >file && + git commit -m author \ + --author "Rubber Duck <[email protected]>" -a >output 2>&1 && + grep Rubber.Duck output +' + +test_expect_success PERL 'interactive add' ' + echo 7 | + git commit --interactive | + grep "What now" +' + +test_expect_success PERL "commit --interactive doesn't change index if editor aborts" ' + echo zoo >file && test_must_fail git diff --exit-code >diff1 && - (echo u ; echo '*' ; echo q) | - (EDITOR=: && export EDITOR && - test_must_fail git commit --interactive) && + (echo u ; echo "*" ; echo q) | + ( + EDITOR=: && + export EDITOR && + test_must_fail git commit --interactive + ) && git diff >diff2 && - test_cmp diff1 diff2" + compare_diff_patch diff1 diff2 +' -cat >editor <<\EOF -#!/bin/sh -sed -e "s/good/bad/g" < "$1" > "$1-" -mv "$1-" "$1" -EOF -chmod 755 editor +test_expect_success 'editor not invoked if -F is given' ' + cat >editor <<-\EOF && + #!/bin/sh + sed -e s/good/bad/g <"$1" >"$1-" + mv "$1-" "$1" + EOF + chmod 755 editor && -cat >msg <<EOF -A good commit message. -EOF + echo A good commit message. >msg && + echo moo >file && -test_expect_success \ - 'editor not invoked if -F is given' ' - echo "moo" >file && - EDITOR=./editor git commit -a -F msg && - git show -s --pretty=format:"%s" | grep -q good && - echo "quack" >file && - echo "Another good message." | EDITOR=./editor git commit -a -F - && - git show -s --pretty=format:"%s" | grep -q good - ' + EDITOR=./editor git commit -a -F msg && + git show -s --pretty=format:%s >subject && + grep -q good subject && + + echo quack >file && + echo Another good message. | + EDITOR=./editor git commit -a -F - && + git show -s --pretty=format:%s >subject && + grep -q good subject +' test_expect_success 'partial commit that involves removal (1)' '
@@ -197,7 +200,6 @@ test_expect_success 'partial commit that involves removal (3)' ' ' -author="The Real Author <[email protected]>" test_expect_success 'amend commit to fix author' ' oldtick=$GIT_AUTHOR_DATE &&
@@ -326,7 +328,6 @@ test_expect_success 'multiple -m' ' ' -author="The Real Author <[email protected]>" test_expect_success 'amend commit to fix author' ' oldtick=$GIT_AUTHOR_DATE &&
@@ -353,15 +354,8 @@ test_expect_success 'git commit <file> with dirty index' ' test_expect_success 'same tree (single parent)' ' - git reset --hard - - if git commit -m empty - then - echo oops -- should have complained - false - else - : happy - fi + git reset --hard && + test_must_fail git commit -m empty '
Signature · 1 line
1.7.8.rc3
PATCH 4/4 test: commit --amend should honor --no-edit
In reply to Jonathan NiederA quick test to make sure git doesn't lose the functionality added by the recent patch "commit: honor --no-edit", plus another test to check the classical --edit use case (use with "-m").
--- t/t7501-commit.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-)
t/t7501-commit.sh +40 -0
@@ -94,6 +94,46 @@ test_expect_success 'amend commit' ' EDITOR=./editor git commit --amend ' +test_expect_success 'set up editor' ' + cat >editor <<-\EOF && + #!/bin/sh + sed -e "s/unamended/amended/g" <"$1" >"$1-" + mv "$1-" "$1" + EOF + chmod 755 editor +' + +test_expect_success 'amend without launching editor' ' + echo unamended >expect && + git commit --allow-empty -m "unamended" && + echo needs more bongo >file && + git add file && + EDITOR=./editor git commit --no-edit --amend && + git diff --exit-code HEAD -- file && + git diff-tree -s --format=%s HEAD >msg && + test_cmp expect msg +' + +test_expect_success '--amend --edit' ' + echo amended >expect && + git commit --allow-empty -m "unamended" && + echo bongo again >file && + git add file && + EDITOR=./editor git commit --edit --amend && + git diff-tree -s --format=%s HEAD >msg && + test_cmp expect msg +' + +test_expect_success '-m --edit' ' + echo amended >expect && + git commit --allow-empty -m buffer && + echo bongo bongo >file && + git add file && + EDITOR=./editor git commit -m unamended --edit && + git diff-tree -s --format=%s HEAD >msg && + test_cmp expect msg +' + test_expect_success '-m and -F do not mix' ' echo enough with the bongos >file && test_must_fail git commit -F msg -m amending .
Signature · 1 line
1.7.8.rc3
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Vijay Lakshminarayanan
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
Are you sure it is a cat?
Yes.
Did you mean something else by your question?
Quoted 3 lines
I almost always use
$ EDITOR=: git commit --amend
I just tried this out. This and Peff's GIT_EDITOR=true silently dwiw but cat is useful to review the commit.
Signature · 4 lines
Cheers ~vijay Gnus should be more complicated.
Thanks guys. This whole session was new to me.
Quoted 4 lines · Vijay Lakshminarayanan
Quoted 2 lines · Junio C Hamano
Quoted 2 lines
Vijay Lakshminarayanan <[email protected]> writes:
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
Are you sure it is a cat?
Yes.
This didn't worked for me. Got following error:
cat: unrecognized option `--amend'
Try `cat --help' for more information.
error: There was a problem with the editor 'cat git commit --amend'. Please supply the message using either -m or -F option. Could not commit staged changes.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I almost always use
$ EDITOR=: git commit --amend
Even this didn't worked for me:
error: pathspec '.git/COMMIT_EDITMSG' did not match any file(s) known to git.
error: There was a problem with the editor 'git commit --amend'. Please supply the message using either -m or -F option.
Could not commit staged changes.
Only "true" worked for me.
Probably, i have an older version of git (version 1.7.2.2)
One more thing. I couldn't get completely how this worked. Maybe any pointers to earlier discussions.
The way i am testing it is:
- Stop after a commit in middle of rebase using "edit" or "e" option
- set EDITOR or GIT_EDITOR
- change files
- git add changed_files
- git rebase --continue
Signature · 1 line
viresh
Quoted 17 lines · Viresh Kumar
Thanks guys. This whole session was new to me.
Quoted 4 lines · Vijay Lakshminarayanan
Quoted 2 lines · Junio C Hamano
Quoted 2 lines
Vijay Lakshminarayanan <[email protected]> writes:
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
Are you sure it is a cat?
Yes.
Quoted 7 lines
This didn't worked for me. Got following error:
cat: unrecognized option `--amend'
Try `cat --help' for more information.
error: There was a problem with the editor 'cat git commit --amend'. Please supply the message using either -m or -F option. Could not commit staged changes.
That looks like you did something like:
export GIT_EDITOR="cat git commit --amend"
But the original command was:
GIT_EDITOR=cat git commit --amend
Notice that there are no quotes and no escaped spaces. This is a shortcut to set GIT_EDITOR to "cat" for just this one command (git commit --amend).
If you want to set the editor in the environment, use just "export GIT_EDITOR=cat" or something like that.
HTH
Björn
Quoted 6 lines · Björn Steinbrink
That looks like you did something like:
export GIT_EDITOR="cat git commit --amend"But the original command was:
GIT_EDITOR=cat git commit --amend
Quoted 6 lines
Notice that there are no quotes and no escaped spaces. This is a shortcut to set
GIT_EDITORto "cat" for just this one command (git commit --amend).If you want to set the editor in the environment, use just "export GIT_EDITOR=cat" or something like that.
Ok. Got it now.
Now, whats the benefit of
GIT_EDITOR=cat git commit --amend
over
git commit --amend -C HEAD
?
Obviously if we have more than one commit to handle during a rebase then, setting editor to cat once, would be good. As now we don't really need to do git commit --amend. We can add commits and continue rebase. But for single commit probably second one looks easier. Isn't it? Or maybe the latest patch from Junio is even better.
Signature · 1 line
viresh
Viresh Kumar <[email protected]> writes:
[snip]
Quoted 9 lines
Now, whats the benefit of
GIT_EDITOR=cat git commit --amend
over
git commit --amend -C HEAD
?
The latter preserves the original timestamp of the commit and other environment variables like GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL whereas GIT_EDITOR=cat (or true or :) are equivalent to opening up the commit in an editor and so consider these variables during execution.
For instance, you could say
$ GIT_EDITOR=cat [email protected] git commit --amend
and the commiter email would be set to [email protected]
Signature · 4 lines
Cheers ~vijay Gnus should be more complicated.
Re: [PATCH 1/4] test: add missing "&&" after echo command
In reply to Jonathan Niedert/t7501-commit.sh test_expect_success \ · line 64
Quoted 11 lines · Jonathan Nieder
t/t7501-commit.sh +1
-1@@ -60,7 +60,7 @@ test_expect_success \ test_expect_success \ "next commit" \ - "echo 'bongo bongo bongo' >file \ + "echo 'bongo bongo bongo' >file && \ git commit -m next -a"
Patch is obviously correct, but isn't the "\" here just superfluous and error-prone? Maybe it should just be dropped from the new version (and possibly from other tests in t7501).
-Peff
Re: [PATCH 1/4] test: add missing "&&" after echo command
Quoted 8 lines · Jeff King
Quoted 6 lines · Jonathan Nieder
t/t7501-commit.sh +0
-0@@ -60,7 +60,7 @@ test_expect_success \
Quoted 9 lines
t/t7501-commit.sh test_expect_success \ · line 64
Quoted 5 lines
t/t7501-commit.sh +1
-1test_expect_success \ "next commit" \ - "echo 'bongo bongo bongo' >file \ + "echo 'bongo bongo bongo' >file && \ git commit -m next -a"Patch is obviously correct, but isn't the "\" here just superfluous and error-prone? Maybe it should just be dropped from the new version (and possibly from other tests in t7501).
Oh, nevermind. I just read your patch 3, which does that and much more. I approve.
-Peff
Quoted 10 lines · Viresh Kumar
GIT_EDITOR=cat git commit --amend
over
git commit --amend -C HEAD
?
...
But for single commit probably second one looks easier. Isn't it?
I saw "--amend -C HEAD" mentioned in some newbie-guide webpages, and I think you just copy/learned from one of them, so it is not entirely your fault, but the combination of --amend and "-C HEAD" is an idiotic thing that happens to work, if you think about what exactly you are telling to the command.
The point of --amend is twofold. One is to let you tweak the contents of what is committed, which is not the topic of this thread, and the other is to allow the user to reuse the log message from the commit being amended, instead of typing the message from scratch.
The "-c <commit>" and its cousin "-C <commit>" options are about telling Git that the user does _not_ want the other usual logic to come up with the initial commit template (e.g. when committing anew, it may read the log template file, when committing a merge, it may read the MERGE_MSG prepared by fmt-merge-msg, and most importantly in this context, when amending, the one that is prepared by the --amend logic is used) kick in at all, and instead wants to start from the log message of the named commit.
So by saying "--amend -C HEAD" you are saying "I want to reuse the log message of the commit I am amending,... eh, scratch that, I instead want to use the log message of the HEAD commit", as if the commit you are amending and HEAD are two different things. That is idiotic.
And you say that only for the side effect that capital "-C" stops the editor.
Compared to that idiotic statement, "EDITOR=: git commit --amend" is a lot saner way to say the same thing in a more direct and straightforward way. "I want to reuse the log message of the commit I am amending, and the editor to use it while running that commit is the command 'true', i.e. the one that does not really touch any line in the text file and successfully exits, because I am not going to change anything".
Of course, if "git commit --amend" honoured "--no-edit", that is even more direct, straightforward and intuitive way to say so ;-)
Quoted 7 lines · Junio C Hamano
So by saying "--amend -C HEAD" you are saying "I want to reuse the log message of the commit I am amending,... eh, scratch that, I instead want to use the log message of the HEAD commit", as if the commit you are amending and HEAD are two different things. That is idiotic.
Of course, if "git commit --amend" honoured "--no-edit", that is even more direct, straightforward and intuitive way to say so ;-)
Got your point. That's correct.
Signature · 1 line
viresh
Quoted 6 lines · Vijay Lakshminarayanan
I've found
$ GIT_EDITOR=cat git commit --amenduseful.
Quoted 8 lines
The benefit of this technique is that it even works for git-rebase -i.
In my typical git usage, I do a lot of git-commit --fixup's. After reaching a level of stability, I change the history with:
GIT_EDITOR=cat git rebase -i --autosquash
and my history is adjusted without requiring manual intervention.
Hi Junio,
After going through autosquash option for rebase, i was wondering if there is a way to create a new commit easily for autosquash.
For autosquash to work, we need to keep the same commit log/title, prefixed with squash! or Fixup! etc. What about adding another option in commit amend which adds squash! or Fixup! automatically. So, manual intervention at all. :)
I don't know if it already exist.
Signature · 1 line
viresh
Quoted 4 lines · Viresh Kumar
For autosquash to work, we need to keep the same commit log/title, prefixed with squash! or Fixup! etc. What about adding another option in commit amend which adds squash! or Fixup! automatically. So, manual intervention at all. :)
Done. It is already there in git commit.
Signature · 1 line
viresh