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

Re: [PATCH] rebase -i: interrupt rebase when "commit --amend" failed during "reword"

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 29, 2011, 20:08 UTC
Message-ID
<7vk46isncq.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1322496952-23819-2-git-send-email-andrew.kw.w@gmail.com>
Andrew Wong <andrew.kw.w@gmail.com> writes:
Show 7 quoted lines
> "commit --amend" could fail in cases like the user empties the commit
> message, or pre-commit failed.  When it fails, rebase should be
> interrupted, rather than ignoring the error and continue on rebasing.
> This gives users a way to gracefully interrupt a "reword" if they
> decided they actually want to do an "edit", or even "rebase --abort".
>
> Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>

Makes sense, especially if "commit" itself failed due to some unknown reason or a refusal from the pre-commit hook. Even though a user could have been using the "empty the commit log message and the original is kept" as a trick to recover from a botched rewording attempt and this change will regress for such use cases, I have a feeling that it does not matter.

Is there anything we should be saying more than "fatal: Cannot amend" to help users when this new "die" triggers? What is the recommended recovery procedure? Run "git commit --amend" after doing whatever is needed to fix the tree (e.g. if pre-commit refused because of a coding style violation, it may involve fixing the tree being committed; if it refused because of a typo in the log message, the tree itself may be OK and nothing needs to be done) and then "git rebase --continue"?

Show 17 quoted lines
>  git-rebase--interactive.sh |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index 804001b..669f378 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -408,7 +408,8 @@ do_next () {
>  		mark_action_done
>  		pick_one $sha1 ||
>  			die_with_patch $sha1 "Could not apply $sha1... $rest"
> -		git commit --amend --no-post-rewrite
> +		git commit --amend --no-post-rewrite ||
> +			die_with_patch $sha1 "Cannot amend commit after successfully picking $sha1... $rest"
>  		record_in_rewritten $sha1
>  		;;
>  	edit|e)
Previous: Andrew WongNext: Andrew Wong
Message 4 of 6 in “BUG. git rebase -i successfully continues (and also skips rewording) when pre-commit hook fails (exits with non-zero code)”
  1. Alexey ShumkinNov 17, 2011
  2. Andrew WongNov 28, 2011
  3. rebase -i: interrupt rebase when "commit --amend" failed during "reword"Andrew Wong, Nov 28, 2011
  4. Junio C HamanoNov 29, 2011
  5. Andrew WongNov 30, 2011
  6. rebase -i: interrupt rebase when "commit --amend" failed during "reword"Andrew Wong, Nov 30, 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.