git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-cherry-pick and git-commit --amend in version 1.7.6.4

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 5, 2011, 23:42 UTC
Message-ID
<7v1uur57l8.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7v62k359ee.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> It's just the "commit --amend" message that says I cannot amend felt
> utterly out of place, immediately after seeing "cherry-pick" that tried to
> pick only one commit did _not_ even start.

After thinking about it a bit more, I am starting to think that it may just be the error message given by "commit --amend".

If the sequence were like this:
    $ edit foo.c ;# I want to fix foo.c in the current branch "master"
    $ EDITOR=: git commit --amend ;# forgot to say "foo.c"
    $ git cherry-pick other~2 other
    [master 48882c9] frotz: update xyzzy
     Author: Jay Soffian <jaysoffian@gmail.com>
     1 files changed, 2 insertions(+), 2 deletions(-)
    error: Your local changes to the following files would be overwritten by merge:
            foo.c
    Please, commit your changes or stash them before you can merge.
    Aborting

Then at this point, amending the commit at HEAD^ is not possible anyway, as it is not at the tip anymore. It is perfectly fine that

    $ git commit --amend foo.c
fails at this point.

It is just that it initially felt irritatingly wrong if I was picking only a single commit "other" that wanted to touch foo.c, like this:

    $ edit foo.c ;# I want to fix foo.c in the current branch "master"
    $ EDITOR=: git commit --amend ;# forgot to say "foo.c"
    $ git cherry-pick other
    error: Your local changes to the following files would be overwritten by merge:
            foo.c
    Please, commit your changes or stash them before you can merge.
    Aborting

At this point, as it says "Please commit your changes", and it is very clear that cherry-pick _correctly_ errored out without touching any of my work, it is natural for me to expect that I can "commit --amend" to fix my eariler mistake.

    $ EDITOR=: git commit --amend foo.c
    fatal: You are in the middle of a cherry-pick -- cannot amend.
This can only worked around halfway:
    $ rm .git/CHERRY_PICK_HEAD
    $ EDITOR=: git commit --amend foo.c
    
Things look OK so far, but then restarting the cherry-pick I wanted to do
after I fixed foo.c would fail like this:
    $ git cherry-pick other
    error: .git/sequencer already exists.
    error: A cherry-pick or revert is in progress.
    hint: Use --continue to continue the operation
    hint: or --reset to forget about it
    fatal: cherry-pick failed

Perhaps it would be a possible solution to teach "cherry-pick --reset" to remove CHERRY_PICK_HEAD and the sequencer state, so that the above transcript would become:

    $ edit foo.c ;# I want to fix foo.c in the current branch "master"
    $ EDITOR=: git commit --amend ;# forgot to say "foo.c"
    $ git cherry-pick other
    error: Your local changes to the following files would be overwritten by merge:
            foo.c
    Please, commit your changes or stash them before you can merge.
    Aborting
    $ EDITOR=: git commit --amend foo.c
    fatal: You are in the middle of a cherry-pick -- cannot amend.
    hint: use "git cherry-pick --reset" to discard the previous cherry-pick.
    $ git cherry-pick --reset
    $ EDITOR=: git commit --amend foo.c
    $ git cherry-pick other
    [master 48882c9] frotz: update nitfol
     Author: Jay Soffian <jaysoffian@gmail.com>
     1 files changed, 2 insertions(+), 2 deletions(-)
At least, that looks like something we _could_ explain to the end users.
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 of 16 in “git-cherry-pick and git-commit --amend in version 1.7.6.4”
  1. Nicolas DichtelOct 5, 2011
  2. Jay SoffianOct 5, 2011
  3. Nicolas DichtelOct 6, 2011
  4. Nicolas DichtelOct 6, 2011
  5. Jay SoffianOct 6, 2011
  6. Nicolas DichtelOct 6, 2011
  7. Jay SoffianOct 6, 2011
  8. Junio C HamanoOct 5, 2011
  9. Jay SoffianOct 5, 2011
  10. Junio C HamanoOct 5, 2011
  11. Jay SoffianOct 5, 2011
  12. Junio C HamanoOct 5, 2011
  13. Jay SoffianOct 6, 2011
  14. Junio C HamanoOct 5, 2011
  15. Junio C HamanoOct 5, 2011
  16. Junio C HamanoOct 6, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.