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

Re: [feature request] Warn about or prevent --amend commits that don't change anything

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 13, 2016, 19:16 UTC
Message-ID
<xmqq4m7t1h8v.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<d2c3365d-6da9-dd58-ae7d-4a2020c6b513@web.de>
Bergi <a.d.bergi@web.de> writes:
Show 7 quoted lines
> when nothing is staged in the index then `git commit` warns about this
> fact with either "nothing to commit, working directory clean" or "no
> changes added to commit".
> However, `git commit --amend --no-edit` will happily record a new
> commit that differs in nothing than its commit date from the original.
>
> This is unexpected and can lead to mistakes.
What kind of "mistake" are you afraid of?

I can sort of see that "git commit --amend" might want to see two summary diffstat output at the end, unlike "git commit" that shows what changes were recorded relative to the parent. In addition to that "final result is different in this way from the parent" output, you might also want "this is the change you made by amending" and knowing the fact that you can notice you didn't add anything by the latter being empty _might_ give you an additional peace of mind.

But is that the kind of mistake you are worried about? IOW, you thought you made and added changes X, Y and Z to the index before running your "commit --amend", but you forgot the "add" step and did not add anything? If so, even the second diff i.e. "this is what you changed by amending" would not help very much, and your "you need --allow-empty if you really do not want any changes to the tree" would not either, if you added X and Y but forgot to add Z.

So I am sensing a slight XY problem here.
Previous: BergiNext: Bergi
Message 2 of 3 in “[feature request] Warn about or prevent --amend commits that don't change anything”
  1. BergiJul 13, 2016
  2. Junio C HamanoJul 13, 2016
  3. BergiJul 13, 2016

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.