Re: git-cherry-pick and git-commit --amend in version 1.7.6.4
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:11
Junio C Hamano [off-list ref] 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 [off-list ref]
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 [off-list ref]
1 files changed, 2 insertions(+), 2 deletions(-)
At least, that looks like something we _could_ explain to the end users.