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

[PATCH] git-commit: Allow to amend a merge commit that does not change the tree

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Dec 3, 2007, 07:24 UTC
Message-ID
<1196666690-22187-1-git-send-email-johannes.sixt@telecom.at>

Normally, it should not be allowed to generate an empty commit. A merge commit generated with git 'merge -s ours' does not change the tree (along the first parent), but merges are not "empty" even if they do not change the tree. Hence, commit 8588452ceb7 allowed to amend a merge commit that does not change the tree, but 4fb5fd5d301 disallowed it again in an attempt to avoid that an existing commit is amended such that it becomes empty. With this change, a commit can be edited (create a new one or amend an existing one) either if there are changes or if there are at least two parents.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
	I need this patch because I sometimes do 'git merge -s ours' and
	then want to change the commit message.
	I haven't gotten around to write a test case for this scenario,
	so I'm sending out the fix alone, in order to draw attention
	to the issue and have builtin-commit fixed by its authors, if
	necessary ;)
	Thanks,
	-- Hannes
 git-commit.sh |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 4853397..1a07278 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -515,13 +515,16 @@ else
 	# we need to check if there is anything to commit
 	run_status >/dev/null
 fi
-if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
-then
+case "$?,$PARENTS" in
+0,* | *,-p*-p*)
+	:	# ok, go ahead
+	;;
+*)
 	rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
 	use_status_color=t
 	run_status
 	exit 1
-fi
+esac
 
 case "$no_edit" in
 '')
-- 
1.5.3.6.969.g3cdf46
Next: Junio C Hamano
Message 1 of 3 in “git-commit: Allow to amend a merge commit that does not change the tree”
  1. git-commit: Allow to amend a merge commit that does not change the treeJohannes Sixt, Dec 3, 2007
  2. Junio C HamanoDec 3, 2007
  3. Junio C HamanoDec 3, 2007

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.