* [feature request] Warn about or prevent --amend commits that don't change anything
@ 2016-07-13 18:56 Bergi
2016-07-13 19:16 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Bergi @ 2016-07-13 18:56 UTC (permalink / raw)
To: git
Hello,
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. Without running `git
status`, the user will not notice that his unstaged changes were not
commited, as everything behaves as expected otherwise (the success
output from `commit`, the new commit id in the log, `push` requiring the
force option, etc).
I understand that `--amend` is (can be) used for editing commit
messages, authors, authoring dates etc.
I would however like to see any `--amend` command that results in no
changes to the tree, the commit message and the authoring metadata
reject the commit with an appropriate warning similar to the one that a
plain `git commit` would present. It should be overrideable by the
`--allow-emtpy` parameter as well.
If this change detection is somehow unfeasible, I would at least like
the `git commit --amend --no-edit` command (with no other flags) to
check the tree in the same way as `git commit` does, as the intention of
`--no-edit` is even more clear and running the command is more obviously
a mistake/lapse.
Kind regards,
Bergi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [feature request] Warn about or prevent --amend commits that don't change anything
2016-07-13 18:56 [feature request] Warn about or prevent --amend commits that don't change anything Bergi
@ 2016-07-13 19:16 ` Junio C Hamano
2016-07-13 21:02 ` Bergi
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2016-07-13 19:16 UTC (permalink / raw)
To: Bergi; +Cc: git
Bergi <a.d.bergi@web.de> writes:
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [feature request] Warn about or prevent --amend commits that don't change anything
2016-07-13 19:16 ` Junio C Hamano
@ 2016-07-13 21:02 ` Bergi
0 siblings, 0 replies; 3+ messages in thread
From: Bergi @ 2016-07-13 21:02 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano schrieb:
> Bergi <a.d.bergi@web.de> writes:
>
>> 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.
>
> What kind of "mistake" are you afraid of?
The particular mistake that happened to me was that I `git push -f
origin`'ed the newly created commit (which worked as expected,
overwriting the original commit) and then leaving my PC in the belief
that I had successfully pushed my changes.
> 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.
Yes, that would be incredibly helpful as well, but is not what I am
after here.
However `git commit --amend` already shows me that I still have "changes
not staged for commit" when editing the commit message, so that would've
been enough for my use case.
The problem is that I used `git commit --amend --no-edit`, which did
neither warn me about missing staged changes nor existing unstaged changes.
If nothing is staged and the user does not intend to edit any metadata,
git should be able to deduce that the user (me) did forget something.
> 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?
Yes, exactly.
> If so, […] your "you need --allow-empty if you really do not want
> any changes to the tree" would not [help much] either, if you added
> X and Y but forgot to add Z.
A good remark.
Maybe in that case it could warn about unstaged edits in the case of
--no-edit but still succeed.
> So I am sensing a slight XY problem here.
That might well be, I'm just here to tell my story, it's the designers
that need to decide at which step I went wrong and which parts could be
improved.
Kind regards,
Bergi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-07-13 21:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-13 18:56 [feature request] Warn about or prevent --amend commits that don't change anything Bergi
2016-07-13 19:16 ` Junio C Hamano
2016-07-13 21:02 ` Bergi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).