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

Re: Query on git commit amend

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 8, 2011, 17:52 UTC
Message-ID
<7vvcprar3v.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4EDEFD66.4020404@st.com>
Viresh Kumar <viresh.kumar@st.com> writes:
Show 10 quoted lines
> GIT_EDITOR=cat git commit --amend
>
> over
>
> git commit --amend -C HEAD
>
> ?
>
> ...
> But for single commit probably second one looks easier. Isn't it?

I saw "--amend -C HEAD" mentioned in some newbie-guide webpages, and I think you just copy/learned from one of them, so it is not entirely your fault, but the combination of --amend and "-C HEAD" is an idiotic thing that happens to work, if you think about what exactly you are telling to the command.

The point of --amend is twofold. One is to let you tweak the contents of what is committed, which is not the topic of this thread, and the other is to allow the user to reuse the log message from the commit being amended, instead of typing the message from scratch.

The "-c <commit>" and its cousin "-C <commit>" options are about telling Git that the user does _not_ want the other usual logic to come up with the initial commit template (e.g. when committing anew, it may read the log template file, when committing a merge, it may read the MERGE_MSG prepared by fmt-merge-msg, and most importantly in this context, when amending, the one that is prepared by the --amend logic is used) kick in at all, and instead wants to start from the log message of the named commit.

So by saying "--amend -C HEAD" you are saying "I want to reuse the log message of the commit I am amending,... eh, scratch that, I instead want to use the log message of the HEAD commit", as if the commit you are amending and HEAD are two different things. That is idiotic.

And you say that only for the side effect that capital "-C" stops the editor.

Compared to that idiotic statement, "EDITOR=: git commit --amend" is a lot saner way to say the same thing in a more direct and straightforward way. "I want to reuse the log message of the commit I am amending, and the editor to use it while running that commit is the command 'true', i.e. the one that does not really touch any line in the text file and successfully exits, because I am not going to change anything".

Of course, if "git commit --amend" honoured "--no-edit", that is even more direct, straightforward and intuitive way to say so ;-)

Previous: Vijay LakshminarayananNext: Viresh Kumar
Message 24 of 27 in “Query on git commit amend”
  1. Viresh KumarDec 6, 2011
  2. Konstantin KhomoutovDec 6, 2011
  3. Dirk SüsserottDec 6, 2011
  4. Johannes SixtDec 6, 2011
  5. Viresh KumarDec 6, 2011
  6. Viresh KumarDec 6, 2011
  7. Vijay LakshminarayananDec 6, 2011
  8. Jeff KingDec 6, 2011
  9. Vijay LakshminarayananDec 7, 2011
  10. Junio C HamanoDec 6, 2011
  11. Junio C HamanoDec 6, 2011
  12. 0/4 Re: commit: honor --no-editJonathan Nieder, Dec 7, 2011
  13. 1/4 test: add missing "&&" after echo commandJonathan Nieder, Dec 7, 2011
  14. Jeff KingDec 7, 2011
  15. Jeff KingDec 7, 2011
  16. 2/4 test: remove a porcelain test that hard-codes commit namesJonathan Nieder, Dec 7, 2011
  17. 3/4 t7501 (commit): modernize styleJonathan Nieder, Dec 7, 2011
  18. 4/4 test: commit --amend should honor --no-editJonathan Nieder, Dec 7, 2011
  19. Vijay LakshminarayananDec 7, 2011
  20. Viresh KumarDec 7, 2011
  21. Björn SteinbrinkDec 7, 2011
  22. Viresh KumarDec 7, 2011
  23. Vijay LakshminarayananDec 7, 2011
  24. Junio C HamanoDec 8, 2011
  25. Viresh KumarDec 9, 2011
  26. Viresh KumarDec 8, 2011
  27. Viresh KumarDec 8, 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.