{"thread":{"id":"42837","subject":"[feature request] Warn about or prevent --amend commits that don't change anything","startedAt":"2016-07-13T18:57:45Z","lastAt":"2016-07-13T21:07:53Z","messageCount":3,"participants":["Bergi","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"291380","messageId":"d2c3365d-6da9-dd58-ae7d-4a2020c6b513@web.de","threadId":"42837","inReplyTo":null,"subject":"[feature request] Warn about or prevent --amend commits that don't change anything","fromName":"Bergi","fromEmail":"a.d.bergi@web.de","sentAt":"2016-07-13T18:56:22Z","receivedAt":"2016-07-13T18:57:45Z","isPatch":false,"sender":{"key":"a.d.bergi@web.de","avatar":null},"body":"Hello,\n\nwhen nothing is staged in the index then `git commit` warns about this \nfact with either \"nothing to commit, working directory clean\" or \"no \nchanges added to commit\".\nHowever, `git commit --amend --no-edit` will happily record a new commit \nthat differs in nothing than its commit date from the original.\n\nThis is unexpected and can lead to mistakes. Without running `git \nstatus`, the user will not notice that his unstaged changes were not \ncommited, as everything behaves as expected otherwise (the success \noutput from `commit`, the new commit id in the log, `push` requiring the \nforce option, etc).\n\nI understand that `--amend` is (can be) used for editing commit \nmessages, authors, authoring dates etc.\nI would however like to see any `--amend` command that results in no \nchanges to the tree, the commit message and the authoring metadata \nreject the commit with an appropriate warning similar to the one that a \nplain `git commit` would present. It should be overrideable by the \n`--allow-emtpy` parameter as well.\n\nIf this change detection is somehow unfeasible, I would at least like \nthe `git commit --amend --no-edit` command (with no other flags) to \ncheck the tree in the same way as `git commit` does, as the intention of \n`--no-edit` is even more clear and running the command is more obviously \na mistake/lapse.\n\nKind regards,\n  Bergi\n"},{"id":"291386","messageId":"xmqq4m7t1h8v.fsf@gitster.mtv.corp.google.com","threadId":"42837","inReplyTo":"d2c3365d-6da9-dd58-ae7d-4a2020c6b513@web.de","subject":"Re: [feature request] Warn about or prevent --amend commits that don't change anything","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-07-13T19:16:00Z","receivedAt":"2016-07-13T19:16:27Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bergi <a.d.bergi@web.de> writes:\n\n> when nothing is staged in the index then `git commit` warns about this\n> fact with either \"nothing to commit, working directory clean\" or \"no\n> changes added to commit\".\n> However, `git commit --amend --no-edit` will happily record a new\n> commit that differs in nothing than its commit date from the original.\n>\n> This is unexpected and can lead to mistakes.\n\nWhat kind of \"mistake\" are you afraid of?\n\nI can sort of see that \"git commit --amend\" might want to see two\nsummary diffstat output at the end, unlike \"git commit\" that shows\nwhat changes were recorded relative to the parent.  In addition to\nthat \"final result is different in this way from the parent\" output,\nyou might also want \"this is the change you made by amending\" and\nknowing the fact that you can notice you didn't add anything by the\nlatter being empty _might_ give you an additional peace of mind.\n\nBut is that the kind of mistake you are worried about?  IOW, you\nthought you made and added changes X, Y and Z to the index before\nrunning your \"commit --amend\", but you forgot the \"add\" step and did\nnot add anything?  If so, even the second diff i.e. \"this is what\nyou changed by amending\" would not help very much, and your \"you\nneed --allow-empty if you really do not want any changes to the\ntree\" would not either, if you added X and Y but forgot to add Z.\n\nSo I am sensing a slight XY problem here.\n"},{"id":"291393","messageId":"ef62d73d-ec85-993d-7bdd-d8214a55699a@web.de","threadId":"42837","inReplyTo":"xmqq4m7t1h8v.fsf@gitster.mtv.corp.google.com","subject":"Re: [feature request] Warn about or prevent --amend commits that don't change anything","fromName":"Bergi","fromEmail":"a.d.bergi@web.de","sentAt":"2016-07-13T21:02:13Z","receivedAt":"2016-07-13T21:07:53Z","isPatch":false,"sender":{"key":"a.d.bergi@web.de","avatar":null},"body":"Junio C Hamano schrieb:\n> Bergi <a.d.bergi@web.de> writes:\n>\n>> when nothing is staged in the index then `git commit` warns about this\n>> fact with either \"nothing to commit, working directory clean\" or \"no\n>> changes added to commit\".\n>> However, `git commit --amend --no-edit` will happily record a new\n>> commit that differs in nothing than its commit date from the original.\n>\n> What kind of \"mistake\" are you afraid of?\n\nThe particular mistake that happened to me was that I `git push -f \norigin`'ed the newly created commit (which worked as expected, \noverwriting the original commit) and then leaving my PC in the belief \nthat I had successfully pushed my changes.\n\n> I can sort of see that \"git commit --amend\" might want to see two\n> summary diffstat output at the end, unlike \"git commit\" that shows\n> what changes were recorded relative to the parent.  In addition to\n> that \"final result is different in this way from the parent\" output,\n> you might also want \"this is the change you made by amending\" and\n> knowing the fact that you can notice you didn't add anything by the\n> latter being empty _might_ give you an additional peace of mind.\n\nYes, that would be incredibly helpful as well, but is not what I am \nafter here.\n\nHowever `git commit --amend` already shows me that I still have \"changes \nnot staged for commit\" when editing the commit message, so that would've \nbeen enough for my use case.\nThe problem is that I used `git commit --amend --no-edit`, which did \nneither warn me about missing staged changes nor existing unstaged changes.\nIf nothing is staged and the user does not intend to edit any metadata, \ngit should be able to deduce that the user (me) did forget something.\n\n> But is that the kind of mistake you are worried about?  IOW, you\n> thought you made and added changes X, Y and Z to the index before\n> running your \"commit --amend\", but you forgot the \"add\" step and did\n> not add anything?\n\nYes, exactly.\n\n> If so, […] your \"you need --allow-empty if you really do not want\n> any changes to the tree\" would not [help much] either, if you added\n> X and Y but forgot to add Z.\n\nA good remark.\nMaybe in that case it could warn about unstaged edits in the case of \n--no-edit but still succeed.\n\n> So I am sensing a slight XY problem here.\n\nThat might well be, I'm just here to tell my story, it's the designers \nthat need to decide at which step I went wrong and which parts could be \nimproved.\n\nKind regards,\n  Bergi\n"}]}