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

[PATCH v2] git-rebase--interactive: auto amend only edited commit

From
Dmitry Potapov <dpotapov@gmail.com>
Date
Sep 9, 2008, 12:05 UTC
Message-ID
<1220961926-13235-1-git-send-email-dpotapov@gmail.com>
In-Reply-To
<20080909070055.GB28210@dpotapov.dyndns.org>

"git rebase --continue" issued after git rebase being stop by "edit" command is trying to amend the last commit using stage changes. However, if the last commit is not the commit that was marked as "edit" then it can produce unexpected results.

For instance, after being stop by "edit", I have made some changes to commit message using "git commit --amend". After that I realized that I forgot to add some changes to some file. So, I said "git add file" and the "git rebase --continue". Unfortunately, it caused that the new commit message was lost.

Another problem is that after being stopped at "edit", the user adds new commits. In this case, automatic amend behavior of git rebase triggered by some stage changes causes that not only that the log message of the last commit is lost but that it will contain also wrong Author and Date information.

Therefore, this patch restrict automatic amend only to the situation where HEAD is the commit at which git rebase stop by "edit" command.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
Changes:
 1. I have correct the obvious bug pointed by Junio.
 2. The error message is more verbose now.
 git-rebase--interactive.sh |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5b2b1e5..d2aa954 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -284,7 +284,7 @@ do_next () {
 		pick_one $sha1 ||
 			die_with_patch $sha1 "Could not apply $sha1... $rest"
 		make_patch $sha1
-		: > "$DOTEST"/amend
+		git rev-parse --verify HEAD > "$DOTEST"/amend
 		warn "Stopped at $sha1... $rest"
 		warn "You can amend the commit now, with"
 		warn
@@ -430,6 +430,10 @@ do
 			if test -f "$DOTEST"/amend
 			then
 				amend=$(git rev-parse --verify HEAD)
+				test "$amend" = $(cat "$DOTEST"/amend) ||
+				die "\
+You have uncommitted changes in your working tree. Please, commit them
+first and then run 'git rebase --continue' again."
 				git reset --soft HEAD^ ||
 				die "Cannot rewind the HEAD"
 			fi
-- 
1.6.0
Previous: Dmitry PotapovNext: Johannes Sixt
Message 5 of 12 in “git-rebase-interactive: do not squash commits on abort”
  1. 1/2 git-rebase-interactive: do not squash commits on abortDmitry Potapov, Sep 8, 2008
  2. 2/2 git-rebase--interactive: auto amend only edited commitDmitry Potapov, Sep 8, 2008
  3. Junio C HamanoSep 9, 2008
  4. Dmitry PotapovSep 9, 2008
  5. git-rebase--interactive: auto amend only edited commitDmitry Potapov, Sep 9, 2008
  6. Johannes SixtSep 9, 2008
  7. Dmitry PotapovSep 9, 2008
  8. Junio C HamanoSep 9, 2008
  9. Johannes SchindelinSep 9, 2008
  10. git-rebase-interactive: do not squash commits on abortDmitry Potapov, Sep 9, 2008
  11. Johannes SchindelinSep 10, 2008
  12. Junio C HamanoSep 10, 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.