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

Re: [PATCH] additional help when editing during interactive rebase

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 11, 2008, 11:29 UTC
Message-ID
<Pine.LNX.4.64.0801111147440.14355@wbgn129.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vprw83g8z.fsf@gitster.siamese.dyndns.org>
Hi,
On Fri, 11 Jan 2008, Junio C Hamano wrote:
Show 13 quoted lines
> Do you mean you would instead suggest "git rebase --continue" in
> the insn, and make the workflow like this:
> 
> 	$ git rebase -i ...
>         Now do whatever you want and say "rebase --continue"
> 	$ edit foo.c
>         $ git add foo.c
>         $ git rebase --continue
> 
> and have "rebase --continue" to continue with the modified
> contents recorded in the index, invoking "git commit --amend",
> but doing so only if the user hasn't run "git commit" with or
> without --amend yet?
Yes, exactly.
> It feels like a better automation than what we currently have,
> but I somewhat worry how that would change the user experience
> for using 'edit' to split a commit into two or more.

If you want to split a commit into two or more, you will already have committed twice when you say "--continue", and all is fine.

However, if you do the first commit, and then only add the files for the second commit, the HEAD's commit name has changed! And so, rebase can pick up on that, and avoid the --amend.

IOW something like below. However, this patch does not yet make "rebase -i" call "commit --amend" automatically when both the index and HEAD are unchanged.

-- snipsnap -- [PATCH] rebase -i: only ever commit --amend when HEAD is untouched

When a commit is marked to edit, and the index is dirty when "rebase --continue" is called, that state will be committed with the "--amend" option.

However, this is wrong when the user wanted to split the commit.

Luckily, we can pick up on that, by recording the HEAD's name in the file "amend", and only --amend when no commit was made in the interim.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 git-rebase--interactive.sh |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index acdcc54..4a8a980 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -257,7 +257,7 @@ do_next () {
 		pick_one $sha1 ||
 			die_with_patch $sha1 "Could not apply $sha1... $rest"
 		make_patch $sha1
-		: > "$DOTEST"/amend
+		git rev-parse HEAD > "$DOTEST"/amend
 		warn
 		warn "You can amend the commit now, with"
 		warn
@@ -378,7 +378,9 @@ do
 		else
 			. "$DOTEST"/author-script ||
 				die "Cannot find the author identity"
-			if test -f "$DOTEST"/amend
+			if test -f "$DOTEST"/amend &&
+				test $(git rev-parse HEAD) = \
+					$(cat "$DOTEST"/amend)
 			then
 				git reset --soft HEAD^ ||
 				die "Cannot rewind the HEAD"
Previous: Junio C Hamano
Message 6 of 6 in “additional help when editing during interactive rebase”
  1. additional help when editing during interactive rebaseWilliam Morgan, Jan 9, 2008
  2. Junio C HamanoJan 9, 2008
  3. additional help when editing during interactive rebaseWilliam Morgan, Jan 9, 2008
  4. Johannes SchindelinJan 9, 2008
  5. Junio C HamanoJan 11, 2008
  6. Johannes SchindelinJan 11, 2008

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.