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

Re: modifying commit's author

From
Junio C Hamano <junkio@cox.net>
Date
Jan 22, 2007, 21:03 UTC
Message-ID
<7vwt3ercyk.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7v8xfuss84.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
Show 18 quoted lines
> "J. Bruce Fields" <bfields@fieldses.org> writes:
>
>> If I got the author wrong on a commit, is there a quick way to fix it
>> (e.g. by passing the right arguments or environment variables to commit
>> --amend)?
>
> I usually do "format-patch -$n; reset --hard HEAD~$n; edit
> 00??-*.patch; am 00??-*.patch" myself when I got into that
> situation to rebuild the branch, and haven't personally felt
> need for an option to --amend, but it might make sense to teach
> git-commit --amend to allow --author option to override it; I
> think it currently ignores --author when given without erroring
> out.
>
> It may become a question if we would want to allow updating the
> timestamp as well, but when people asked for --author I did not
> hear from anybody who wanted to have --authortime, so not being
> able to do so probably is Ok.
Untested, but something along this line.

-- >8 -- [PATCH] honor --author even with --amend, -C, and -c.

Earlier code discarded GIT_AUTHOR_DATE taken from the base commit when --author was specified. This was often wrong as that use is likely to fix the spelling of author's name.

---
diff --git a/git-commit.sh b/git-commit.sh
index e23918c..6f4dcdb 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -462,15 +462,7 @@ if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
 fi >>"$GIT_DIR"/COMMIT_EDITMSG
 
 # Author
-if test '' != "$force_author"
-then
-	GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
-	GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
-	test '' != "$GIT_AUTHOR_NAME" &&
-	test '' != "$GIT_AUTHOR_EMAIL" ||
-	die "malformed --author parameter"
-	export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
-elif test '' != "$use_commit"
+if test '' != "$use_commit"
 then
 	pick_author_script='
 	/^author /{
@@ -501,6 +493,15 @@ then
 	export GIT_AUTHOR_EMAIL
 	export GIT_AUTHOR_DATE
 fi
+if test '' != "$force_author"
+then
+	GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
+	GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
+	test '' != "$GIT_AUTHOR_NAME" &&
+	test '' != "$GIT_AUTHOR_EMAIL" ||
+	die "malformed --author parameter"
+	export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
+fi
 
 PARENTS="-p HEAD"
 if test -z "$initial_commit"
Previous: J. Bruce FieldsNext: Robin Rosenberg
Message 4 of 7 in “modifying commit's author”
  1. J. Bruce FieldsJan 22, 2007
  2. Junio C HamanoJan 22, 2007
  3. J. Bruce FieldsJan 22, 2007
  4. Junio C HamanoJan 22, 2007
  5. Robin RosenbergJan 22, 2007
  6. J. Bruce FieldsJan 22, 2007
  7. Johannes SixtJan 23, 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.