{"thread":{"id":"38548","subject":"Keep original author with git merge --squash?","startedAt":"2015-02-11T17:21:04Z","lastAt":"2015-02-13T19:55:28Z","messageCount":18,"participants":["David Glasser","Jeff King","Michael Haggerty","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"255935","messageId":"CAN7QDoKQAZKUt_MHWjgt1k3PvXQv6XTcjdijh8KRodO3=VD47A@mail.gmail.com","threadId":"38548","inReplyTo":null,"subject":"Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-11T17:21:04Z","receivedAt":"2015-02-11T17:21:04Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"I frequently find myself using `git merge --squash` to combine a\nseries of commits by the same author into one.\n\n(For example, I fetch my project's GitHub PRs into my repo.\nFrequently, a PR consists of the original PR (with a good description)\nfollowed by a few follow-ups based on feedback from me.  While I'd\nprefer that the submitter amended their original commit instead of\nmaking it my job, this is rare.  And I don't feel that it's valuable\nto my project's git history to contain all the intermediate stages of\ncode review --- it's usually just one commit.)\n\nSo `git merge --squash origin/pr/1234` is a really convenient command\nhere... except for one thing: it sets the author as me.  I always have\nto manually find the author line and make sure to pass it to --author\n(perhaps with --amend).\n\nWhat would people think of a flag (or a config value) that means \"if\nall merged commits are by the same author, use that author for the\nresulting commit instead of the default author\"?\n\n(I'm not sure if this should be a flag to --squash or to commit.\nMaybe `git merge --squash`; `git commit --use-squashed-author`?  Seems\nlike it should be not too hard to implement; SQUASH_MSG is pretty\nparseable.  Or just a config value.)\n\n--dave\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"255961","messageId":"20150212092824.GA19626@peff.net","threadId":"38548","inReplyTo":"CAN7QDoKQAZKUt_MHWjgt1k3PvXQv6XTcjdijh8KRodO3=VD47A@mail.gmail.com","subject":"Re: Keep original author with git merge --squash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-12T09:28:24Z","receivedAt":"2015-02-12T09:28:24Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 11, 2015 at 09:21:04AM -0800, David Glasser wrote:\n\n> (I'm not sure if this should be a flag to --squash or to commit.\n> Maybe `git merge --squash`; `git commit --use-squashed-author`?  Seems\n> like it should be not too hard to implement; SQUASH_MSG is pretty\n> parseable.  Or just a config value.)\n\nIt sounds like \"git commit -c\" is close to what you want, which will\npull the author and commit message from a particular commit. But I don't\nthink there is a convenient way to name the commit in your case (it is\nlikely to be the first commit on the branch you are squash-merging, but\nthere isn't a shorthand for that).\n\nI assume you are already munging in your editor the template provided by\n\"git commit\" after the squash? What would be really nice, IMHO, is if\nthere was a way to set the author during that edit (e.g., by moving one\nof the \"Author:\" lines to the top of the file). That would cover your\nuse case, I think, and would also be useful in general.\n\n-Peff\n"},{"id":"255981","messageId":"54DC9014.1010200@alum.mit.edu","threadId":"38548","inReplyTo":"20150212092824.GA19626@peff.net","subject":"Re: Keep original author with git merge --squash?","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2015-02-12T11:35:48Z","receivedAt":"2015-02-12T11:35:48Z","isPatch":false,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 02/12/2015 10:28 AM, Jeff King wrote:\n> On Wed, Feb 11, 2015 at 09:21:04AM -0800, David Glasser wrote:\n> \n>> (I'm not sure if this should be a flag to --squash or to commit.\n>> Maybe `git merge --squash`; `git commit --use-squashed-author`?  Seems\n>> like it should be not too hard to implement; SQUASH_MSG is pretty\n>> parseable.  Or just a config value.)\n> \n> It sounds like \"git commit -c\" is close to what you want, which will\n> pull the author and commit message from a particular commit. But I don't\n> think there is a convenient way to name the commit in your case (it is\n> likely to be the first commit on the branch you are squash-merging, but\n> there isn't a shorthand for that).\n> \n> I assume you are already munging in your editor the template provided by\n> \"git commit\" after the squash? What would be really nice, IMHO, is if\n> there was a way to set the author during that edit (e.g., by moving one\n> of the \"Author:\" lines to the top of the file). That would cover your\n> use case, I think, and would also be useful in general.\n\nIf only Git supported options on todo list lines [1], this could be\nimplemented via a \"--use-author\" option:\n\n    pick --use-author 1234556 blah\n    squash 84392ab etc\n    fixup 49106a5 another\n\nHappily, this would work with fixup, too, without forcing the user to go\ninto the editor. Also, it wouldn't require metadata to be read in-band\nfrom the commit message.\n\nMichael\n\n[1] http://article.gmane.org/gmane.comp.version-control.git/255410\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"255984","messageId":"20150212121258.GA28801@peff.net","threadId":"38548","inReplyTo":"54DC9014.1010200@alum.mit.edu","subject":"Re: Keep original author with git merge --squash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-12T12:12:58Z","receivedAt":"2015-02-12T12:12:58Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 12, 2015 at 12:35:48PM +0100, Michael Haggerty wrote:\n\n> > I assume you are already munging in your editor the template provided by\n> > \"git commit\" after the squash? What would be really nice, IMHO, is if\n> > there was a way to set the author during that edit (e.g., by moving one\n> > of the \"Author:\" lines to the top of the file). That would cover your\n> > use case, I think, and would also be useful in general.\n> \n> If only Git supported options on todo list lines [1], this could be\n> implemented via a \"--use-author\" option:\n> \n>     pick --use-author 1234556 blah\n>     squash 84392ab etc\n>     fixup 49106a5 another\n> \n> Happily, this would work with fixup, too, without forcing the user to go\n> into the editor. Also, it wouldn't require metadata to be read in-band\n> from the commit message.\n\nYes, that would be nice, but I don't think David is using a sequencer\ntodo list here at all. It's just:\n\n  git merge --squash pr/100\n  git commit\n\n-Peff\n"},{"id":"256002","messageId":"CAN7QDoLEbq47ic61_Bryz1yS=dk5WUGuhuGmmi-jY4eZ9qQ6ng@mail.gmail.com","threadId":"38548","inReplyTo":"20150212121258.GA28801@peff.net","subject":"Re: Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-12T18:42:10Z","receivedAt":"2015-02-12T18:42:10Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"On Thu, Feb 12, 2015 at 4:12 AM, Jeff King <peff@peff.net> wrote:\n> On Thu, Feb 12, 2015 at 12:35:48PM +0100, Michael Haggerty wrote:\n>\n>> > I assume you are already munging in your editor the template provided by\n>> > \"git commit\" after the squash? What would be really nice, IMHO, is if\n>> > there was a way to set the author during that edit (e.g., by moving one\n>> > of the \"Author:\" lines to the top of the file). That would cover your\n>> > use case, I think, and would also be useful in general.\n>>\n>> If only Git supported options on todo list lines [1], this could be\n>> implemented via a \"--use-author\" option:\n>>\n>>     pick --use-author 1234556 blah\n>>     squash 84392ab etc\n>>     fixup 49106a5 another\n>>\n>> Happily, this would work with fixup, too, without forcing the user to go\n>> into the editor. Also, it wouldn't require metadata to be read in-band\n>> from the commit message.\n>\n> Yes, that would be nice, but I don't think David is using a sequencer\n> todo list here at all. It's just:\n>\n>   git merge --squash pr/100\n>   git commit\n\nThat's correct. I certainly know how to do\n\n  git checkout pr/100\n  git rebase -i master  # set things to squash, etc\n  git checkout master\n  git merge pr/100  # or cherry-pick or whatever\n\nAnd that's how I always used to do it.  But `merge --squash` is so\nmuch more convenient... except for the minor wrinkle of needing an\nextra manual step to give the original author their credit.\n\n--dave\n\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"256014","messageId":"xmqqpp9erihg.fsf@gitster.dls.corp.google.com","threadId":"38548","inReplyTo":"20150212092824.GA19626@peff.net","subject":"Re: Keep original author with git merge --squash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-12T20:18:51Z","receivedAt":"2015-02-12T20:18:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Feb 11, 2015 at 09:21:04AM -0800, David Glasser wrote:\n>\n>> (I'm not sure if this should be a flag to --squash or to commit.\n>> Maybe `git merge --squash`; `git commit --use-squashed-author`?  Seems\n>> like it should be not too hard to implement; SQUASH_MSG is pretty\n>> parseable.  Or just a config value.)\n>\n> It sounds like \"git commit -c\" is close to what you want, which will\n> pull the author and commit message from a particular commit. But I don't\n> think there is a convenient way to name the commit in your case (it is\n> likely to be the first commit on the branch you are squash-merging, but\n> there isn't a shorthand for that).\n\nI thought David was primarily interested in the case where a branch\nauthored by a single person, so specifying the tip of the branch\nbeing \"merged\" would be sufficient, no?\n"},{"id":"256021","messageId":"CAN7QDoLKFBCJpFa+QL8dPQtwyAyDNt-ck_sNJ3fS+vTrK_Lg9w@mail.gmail.com","threadId":"38548","inReplyTo":"xmqqpp9erihg.fsf@gitster.dls.corp.google.com","subject":"Re: Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-12T20:53:33Z","receivedAt":"2015-02-12T20:53:33Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"On Thu, Feb 12, 2015 at 12:18 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jeff King <peff@peff.net> writes:\n>\n>> On Wed, Feb 11, 2015 at 09:21:04AM -0800, David Glasser wrote:\n>>\n>>> (I'm not sure if this should be a flag to --squash or to commit.\n>>> Maybe `git merge --squash`; `git commit --use-squashed-author`?  Seems\n>>> like it should be not too hard to implement; SQUASH_MSG is pretty\n>>> parseable.  Or just a config value.)\n>>\n>> It sounds like \"git commit -c\" is close to what you want, which will\n>> pull the author and commit message from a particular commit. But I don't\n>> think there is a convenient way to name the commit in your case (it is\n>> likely to be the first commit on the branch you are squash-merging, but\n>> there isn't a shorthand for that).\n>\n> I thought David was primarily interested in the case where a branch\n> authored by a single person, so specifying the tip of the branch\n> being \"merged\" would be sufficient, no?\n\nWell, using -c appears to override SQUASH_MSG entirely; it replaces\nthe message as well as the author.  Often I do want to make my own\nmessage based on all the messages provided by the submitter.  (And\ntypically the branch's tip is the least useful message anyway: it's\nusually something like \"respond to code review\".)\n\n--dave\n\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"256023","messageId":"xmqq8ug2rfi2.fsf@gitster.dls.corp.google.com","threadId":"38548","inReplyTo":"CAN7QDoLKFBCJpFa+QL8dPQtwyAyDNt-ck_sNJ3fS+vTrK_Lg9w@mail.gmail.com","subject":"Re: Keep original author with git merge --squash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-12T21:23:17Z","receivedAt":"2015-02-12T21:23:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Glasser <glasser@davidglasser.net> writes:\n\n> Well, using -c appears to override SQUASH_MSG entirely; it replaces\n> the message as well as the author.  Often I do want to make my own\n> message based on all the messages provided by the submitter.  (And\n> typically the branch's tip is the least useful message anyway: it's\n> usually something like \"respond to code review\".)\n\nI wonder if there is a bug in the workflow.  Isn't the contributor\nforcing more work to the integrator that way and making it a\nresponsibility of the integrator to squash multiple commits into\none, instead of asking a cleaned-up branch to be merged in the first\nplace?  It is a key to keep your project scalable to push as much\nwork out of the integrator's plate to the contributors' plates.\n\nBut that is an unrelated tangent.  Among the ideas floated in the\nthread, I tend to like something like what Peff mentioned earlier.\n\n> I assume you are already munging in your editor the template provided by\n> \"git commit\" after the squash? What would be really nice, IMHO, is if\n> there was a way to set the author during that edit (e.g., by moving one\n> of the \"Author:\" lines to the top of the file). That would cover your\n> use case, I think, and would also be useful in general.\n\nI don't know if the exact solution Peff mentioned is good [*1*], but\nbeing able to do an equivalent of setting --author=\"<author>\" and\n\"--date=<date>\" from the command line inside the log message editor\nwould be a huge win.\n\n\n[Footnote]\n\n*1* You would see\n\n\tgostak: do not distim doshes unconditionally\n\n\tUsually it is a good idea to let gostak distim doshes,\n        but it should cause the program segfault when there is\n        no doshes to be distimmed.  Detect this case and error\n        out.\n\n\tSigned-off-by: David Glasser <glasser@davidglasser.net>\n\n        # Please enter the commit message ...\n        #\n        # Author:    David Glasser <glasser@davidglasser.net>\n        # Date:      Thu, 12 Feb 2015 04:28:24 -0500\n        # ...\n\nwhen you start \"git commit --amend\" or \"git merge --squash\", and the\nproposal, as I understand it, is to allow you to do this:\n\n        From: David Glasser <glasser@davidglasser.net>\n        Date: Thu, 12 Feb 2015 04:28:24 -0500\n\n\tgostak: do not distim doshes unconditionally\n\n\tUsually it is a good idea to let gostak distim doshes,\n        but it should cause the program segfault when there is\n        no doshes to be distimmed.  Detect this case and error\n        out.\n\n\tSigned-off-by: David Glasser <glasser@davidglasser.net>\n\n        # Please enter the commit message ...\n        #\n        # ...\n\nwhich is the same format of the _body_ of the message \"git am\" would\ntake.  The reason I am not so sure about such a change is that\nhaving to move and edit things would be error prone.  Some may\nforget to do s/Author:/From:/ and we would end up having to support\nboth.  Some existing commit may validly have lines that begin with\nthese tokens (\"git am\" does not have such a problem because it is\nnot the underlying \"git commit\" or \"git commit-tree\" that interprets\nthese in-body headers).  Some users may forget to leave a blank line\nbetween the in-body headers and the subject line.\n\nI suspect that it _might_ work better if we always look for the pair\nof \"# Author: \" and \"# Date:\" lines (taking the commentchar setting\nin to account, of course) immediately at the beginning of the\ntrailing comment block, and if exists, use that to override the\nauthorship identity.  If the user does not do anything when running\n\"git commit --amend\", the resulting commit will get the original\nauthorship.  If the user strips all the lines in the trailing\ncomment block, we would do the same thing as we have always done and\nretain the original authorship.\n\nI dunno.\n"},{"id":"256025","messageId":"CAN7QDoJ+hOFqoc54sAbLeSxvj8TQKQRSVKbNQXZYfPv1uOy=WA@mail.gmail.com","threadId":"38548","inReplyTo":"xmqq8ug2rfi2.fsf@gitster.dls.corp.google.com","subject":"Re: Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-12T22:16:25Z","receivedAt":"2015-02-12T22:16:25Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"On Thu, Feb 12, 2015 at 1:23 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> David Glasser <glasser@davidglasser.net> writes:\n>\n>> Well, using -c appears to override SQUASH_MSG entirely; it replaces\n>> the message as well as the author.  Often I do want to make my own\n>> message based on all the messages provided by the submitter.  (And\n>> typically the branch's tip is the least useful message anyway: it's\n>> usually something like \"respond to code review\".)\n>\n> I wonder if there is a bug in the workflow.  Isn't the contributor\n> forcing more work to the integrator that way and making it a\n> responsibility of the integrator to squash multiple commits into\n> one, instead of asking a cleaned-up branch to be merged in the first\n> place?  It is a key to keep your project scalable to push as much\n> work out of the integrator's plate to the contributors' plates.\n>\n> But that is an unrelated tangent.  Among the ideas floated in the\n> thread, I tend to like something like what Peff mentioned earlier.\n\nYes, I agree that the GitHub pull request workflow has some major\ndisadvantages. It does a good job of enabling unsophisticated\ncontributors who aren't git experts to propose changes to a codebase,\nbut not a very good job of encouraging them to do the work of\nmassaging what may be a series of changes as the patch undergoes code\nreview into a single patch (or well-structured series of patches).  At\nthis point in time, the tradeoff of requiring a little more integrator\nwork makes sense for my project.  I'd rather spend my limited \"educate\npotential contributors\" energy on ensuring that they include actual\nreproductions with their bug reports than on getting them to do\nadministrative git work that isn't hard for me.\n\nSo to be concrete: What I'm proposing (and I'm excited to implement\nit!) is the following:\n\nWhen running \"git commit\" and:\n- You've fallen into the case where the message was read from SQUASH_MSG\n- You haven't used another method of specifying the author (--author,\n  -C, -c, --amend)\n- You have not specified --reset-author\n- You have set the \"commit.useSquashAuthor\" option\n- Before invoking prepare-commit-msg, all of the `Author:` lines found\n  in SQUASH_MSG have the same value\n\nthen that author is used, as if it were specified with --author.  (And\nthis will show up, commented-out, at the bottom of COMMIT_EDITMSG.)\n\nIf you have the config option set but you don't want this logic to\ntake place for a particular post-squash merge, just specify\n--reset-author.\n\nI think this makes git more internally consistent, since it makes\n`merge --squash` act more like the squash rebase action.  (Personally\nI'd be happy if this behavior was the default, but since it is not\nbackwards-compatible I've included a config option in my\nproposal.)\n\n(It is my understanding, based on reading the code, that the format of\nSQUASH_MSG is not user-configurable, and that scanning for Author:\nlines in it is straightforward.)\n\n--dave\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"256026","messageId":"CAN7QDo+OnMUXtj7rYqxAT+pMMVyCrySqxn4vtwvFY+kD2WEvLQ@mail.gmail.com","threadId":"38548","inReplyTo":"CAN7QDoJ+hOFqoc54sAbLeSxvj8TQKQRSVKbNQXZYfPv1uOy=WA@mail.gmail.com","subject":"Re: Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-12T22:19:24Z","receivedAt":"2015-02-12T22:19:24Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"On Thu, Feb 12, 2015 at 2:16 PM, David Glasser <glasser@davidglasser.net> wrote:\n> - Before invoking prepare-commit-msg, all of the `Author:` lines found\n>   in SQUASH_MSG have the same value\n\nOK, and to be very specific: I'm just proposing \"literally the same\ntext written after Author\"; using mailmap to detect that multiple\ndifferent Author lines are actually the same author could be a\npotential later improvement.\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"256028","messageId":"xmqq4mqqrc70.fsf@gitster.dls.corp.google.com","threadId":"38548","inReplyTo":"CAN7QDoJ+hOFqoc54sAbLeSxvj8TQKQRSVKbNQXZYfPv1uOy=WA@mail.gmail.com","subject":"Re: Keep original author with git merge --squash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-12T22:34:43Z","receivedAt":"2015-02-12T22:34:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Glasser <glasser@davidglasser.net> writes:\n\n> So to be concrete: What I'm proposing (and I'm excited to implement\n> it!) is the following:\n>\n> When running \"git commit\" and:\n> - You've fallen into the case where the message was read from SQUASH_MSG\n> - You haven't used another method of specifying the author (--author,\n>   -C, -c, --amend)\n> - You have not specified --reset-author\n> - You have set the \"commit.useSquashAuthor\" option\n> - Before invoking prepare-commit-msg, all of the `Author:` lines found\n>   in SQUASH_MSG have the same value\n>\n> then that author is used, as if it were specified with --author.  (And\n> this will show up, commented-out, at the bottom of COMMIT_EDITMSG.)\n\n\nI actually was hoping that this would extend to cases other than\n\"git merge --squash\".\n\nWhen running \"git commit\" and:\n\n - You didn't use a more explicit method of specifying the\n   authorship identity (--author, --date, -C, -c --amend,\n   --reset-author options, or environment variables GIT_AUTHOR_*);\n\n - You have commit.useAuthorFromEditorComment variable;\n\n - You have \"# Author: \" line that are identical in the result of\n   the editor,\n\nthen use that author.  That would allow \"git commit --amend\" to\nupdate a misspelled author name, for example.\n\nIs that a bit too liberal?  Would it invite mistakes?\n"},{"id":"256030","messageId":"20150212225003.GA20763@peff.net","threadId":"38548","inReplyTo":"xmqq4mqqrc70.fsf@gitster.dls.corp.google.com","subject":"Re: Keep original author with git merge --squash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-12T22:50:03Z","receivedAt":"2015-02-12T22:50:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 12, 2015 at 02:34:43PM -0800, Junio C Hamano wrote:\n\n> I actually was hoping that this would extend to cases other than\n> \"git merge --squash\".\n> \n> When running \"git commit\" and:\n> \n>  - You didn't use a more explicit method of specifying the\n>    authorship identity (--author, --date, -C, -c --amend,\n>    --reset-author options, or environment variables GIT_AUTHOR_*);\n> \n>  - You have commit.useAuthorFromEditorComment variable;\n> \n>  - You have \"# Author: \" line that are identical in the result of\n>    the editor,\n> \n> then use that author.  That would allow \"git commit --amend\" to\n> update a misspelled author name, for example.\n> \n> Is that a bit too liberal?  Would it invite mistakes?\n\nI like this direction in general.\n\nWhat happens if there is no \"Author:\" line in the output? Do we do the\nequivalent \"--reset-author\"? That seems slightly error-prone to me. It\nis not uncommon for me to delete to the end file in my editor to drop\ncruft (e.g., in an interactive rebase with a \"squash\" command, I very\noften drop the final commit message, and it is simpler to just delete to\nthe end of file than to delete to the top of the comment block).\n\nI wonder if we should have some markers in the commented-out section\nthat indicate it even exists, like:\n\n  # --- Lines in this section affect the commit authorship ---\n  # Author: ...\n  # ---\n\nOf course that is nice when you are editing an existing Author line, but\nnot so much when you have to remember to type that line yourself\n(because you are adding an author attribution when there was not one\nbefore).\n\nSo probably a saner thing is that a missing \"Author:\" line does nothing,\nand using \"Author: \" (with no text) does a reset.\n\nAlso, on the topic of \"merge --squash\". I never use it myself, but\nhaving experimented with it due to this thread, I found the template it\nsticks into COMMIT_EDITMSG to be horribly unfriendly for munging. For\nexample, with two simple commits, I get:\n\n    Squashed commit of the following:\n    \n    commit 6821a8ac920ed00675e4aec10dcef705211105cd\n    Author: Jeff King <peff@peff.net>\n    Date:   Thu Feb 12 17:39:28 2015 -0500\n    \n        commit subject 2\n    \n        commit body 2\n    \n    commit b0840bb4bbfe00b6ed8c7c4d483f11d126fa2d69\n    Author: Jeff King <peff@peff.net>\n    Date:   Thu Feb 12 17:39:28 2015 -0500\n    \n        commit subject 1\n    \n        commit body 1\n\nI guess that is helpful if you want to keep a complete log of what got\nsquashed, but I doubt that is the common case (if you did, then doing a\nreal merge would probably be in order). But to munge that into a usable\nsingle commit message, I have to:\n\n  1. Drop the header fields. We could mark these with \"#\" instead (which\n     would also make the \"# Author: \" proposal here work.\n\n  2. Reindent all of the actual message lines!\n\n  3. Probably reorder the commit messages, since they are\n     reverse-chronological here.\n\nI would find something like:\n\n    # commit b0840bb4bbfe00b6ed8c7c4d483f11d126fa2d69\n    # Author: Jeff King <peff@peff.net>\n    # Date:   Thu Feb 12 17:39:28 2015 -0500\n    \n    commit subject 1\n    \n    commit body 1\n\n    # ... and then the second commit ...\n\nmuch more friendly, and closer to what interactive rebase's squash does.\nIt also raises a question for the proposal in this thread: if there are\nmultiple \"Author:\" lines, which one do we take? The first, or the last?\nI think in the proposed chronological-order format I just showed, it\nwould make sense to take the first.\n\n-Peff\n"},{"id":"256040","messageId":"xmqqwq3mogdm.fsf@gitster.dls.corp.google.com","threadId":"38548","inReplyTo":"20150212225003.GA20763@peff.net","subject":"Re: Keep original author with git merge --squash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-12T23:32:37Z","receivedAt":"2015-02-12T23:32:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> What happens if there is no \"Author:\" line in the output?\n\nI've been assuming that we would do what the current code does.\n\"git commit --amend\" for example internally remembers who the\noriginal author was and uses that, without paying any attention to\nthe result from the editor.  If there is no \"Author:\", that would\nnot change.\n\nAnd I do not think we need to be able to say \"Oops, I forgot to pass\nthe --reset-author option from the command line\", personally, so...\n\n> So probably a saner thing is that a missing \"Author:\" line does nothing,\n\nyes and\n\n> and using \"Author: \" (with no text) does a reset.\n\nno (I do not think it is wrong per-se, but I do not think such a\ngood idea).\n\n> Also, on the topic of \"merge --squash\". I never use it myself, but\n> having experimented with it due to this thread, I found the template it\n> sticks into COMMIT_EDITMSG to be horribly unfriendly for munging. For\n> example, with two simple commits, I get:\n>\n>     Squashed commit of the following:\n>     \n>     commit 6821a8ac920ed00675e4aec10dcef705211105cd\n>     Author: Jeff King <peff@peff.net>\n>     Date:   Thu Feb 12 17:39:28 2015 -0500\n>     \n>         commit subject 2\n>     \n>         commit body 2\n>     \n>     commit b0840bb4bbfe00b6ed8c7c4d483f11d126fa2d69\n>     Author: Jeff King <peff@peff.net>\n>     Date:   Thu Feb 12 17:39:28 2015 -0500\n>     \n>         commit subject 1\n>     \n>         commit body 1\n>\n> I guess that is helpful if you want to keep a complete log of what got\n> squashed, but I doubt that is the common case (if you did, then doing a\n> real merge would probably be in order).\n\nI think it should show exactly the same thing as \"rebase -i\" squash\ninsn would give you.  People already know how to munge that, right?\n\n> It also raises a question for the proposal in this thread: if there are\n> multiple \"Author:\" lines, which one do we take? The first, or the last?\n\nI was siding with David's \"pay attention to in-buffer Author: only\nwhen all of them agree\".  When squash-merging a branch with two or\nmore authors, we would attribute the authorship silently and\nautomatically to you if you do not do anything special otherwise.\n\nPossible alternatives when multiple \"Author:\"s do not agree are:\n\n - use you who is playing the integrator;\n\n - use the tip;\n\n - use the one that most often appears; or\n\n - error out and ask the user to leave only one (or zero--if you\n   want to take the authorship) by re-attempting \"git commit\".\n"},{"id":"256044","messageId":"CAN7QDoK8ePJW-pM=m0+WpEsiYb_aUdt_YUm3gyBhctY_nWBshA@mail.gmail.com","threadId":"38548","inReplyTo":"xmqq4mqqrc70.fsf@gitster.dls.corp.google.com","subject":"Re: Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-13T00:17:13Z","receivedAt":"2015-02-13T00:17:13Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"On Thu, Feb 12, 2015 at 2:34 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> David Glasser <glasser@davidglasser.net> writes:\n>\n>> So to be concrete: What I'm proposing (and I'm excited to implement\n>> it!) is the following:\n>>\n>> When running \"git commit\" and:\n>> - You've fallen into the case where the message was read from SQUASH_MSG\n>> - You haven't used another method of specifying the author (--author,\n>>   -C, -c, --amend)\n>> - You have not specified --reset-author\n>> - You have set the \"commit.useSquashAuthor\" option\n>> - Before invoking prepare-commit-msg, all of the `Author:` lines found\n>>   in SQUASH_MSG have the same value\n>>\n>> then that author is used, as if it were specified with --author.  (And\n>> this will show up, commented-out, at the bottom of COMMIT_EDITMSG.)\n>\n>\n> I actually was hoping that this would extend to cases other than\n> \"git merge --squash\".\n>\n> When running \"git commit\" and:\n>\n>  - You didn't use a more explicit method of specifying the\n>    authorship identity (--author, --date, -C, -c --amend,\n>    --reset-author options, or environment variables GIT_AUTHOR_*);\n>\n>  - You have commit.useAuthorFromEditorComment variable;\n>\n>  - You have \"# Author: \" line that are identical in the result of\n>    the editor,\n>\n> then use that author.  That would allow \"git commit --amend\" to\n> update a misspelled author name, for example.\n>\n> Is that a bit too liberal?  Would it invite mistakes?\n\nThat does sound pretty good.  And for the specific case of squash,\nwhat I would do would be (a) take one of the existing \"Author: \" lines\nand turn it into an \"# Author:\" line and (b) do the ordinary editing\nthat I do to combine the existing messages?\n\n(Maybe my proposed \"detect that they're all the same\" code would run\nat `merge --squash` time, producing a trailing \"# Author:\" line if all\nof the produced \"Author: \" lines were identical?)\n\n--dave\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"256045","messageId":"CAN7QDoKODKwSzWn-Py7zEzbELe4JjoSSjQ7riBRYLcXU-0TLXg@mail.gmail.com","threadId":"38548","inReplyTo":"CAN7QDoK8ePJW-pM=m0+WpEsiYb_aUdt_YUm3gyBhctY_nWBshA@mail.gmail.com","subject":"Re: Keep original author with git merge --squash?","fromName":"David Glasser","fromEmail":"glasser@davidglasser.net","sentAt":"2015-02-13T00:21:56Z","receivedAt":"2015-02-13T00:21:56Z","isPatch":false,"sender":{"key":"glasser@davidglasser.net","avatar":"https://avatars.githubusercontent.com/u/16724?v=4"},"body":"On Thu, Feb 12, 2015 at 4:17 PM, David Glasser <glasser@davidglasser.net> wrote:\n> On Thu, Feb 12, 2015 at 2:34 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> David Glasser <glasser@davidglasser.net> writes:\n>>\n>>> So to be concrete: What I'm proposing (and I'm excited to implement\n>>> it!) is the following:\n>>>\n>>> When running \"git commit\" and:\n>>> - You've fallen into the case where the message was read from SQUASH_MSG\n>>> - You haven't used another method of specifying the author (--author,\n>>>   -C, -c, --amend)\n>>> - You have not specified --reset-author\n>>> - You have set the \"commit.useSquashAuthor\" option\n>>> - Before invoking prepare-commit-msg, all of the `Author:` lines found\n>>>   in SQUASH_MSG have the same value\n>>>\n>>> then that author is used, as if it were specified with --author.  (And\n>>> this will show up, commented-out, at the bottom of COMMIT_EDITMSG.)\n>>\n>>\n>> I actually was hoping that this would extend to cases other than\n>> \"git merge --squash\".\n>>\n>> When running \"git commit\" and:\n>>\n>>  - You didn't use a more explicit method of specifying the\n>>    authorship identity (--author, --date, -C, -c --amend,\n>>    --reset-author options, or environment variables GIT_AUTHOR_*);\n>>\n>>  - You have commit.useAuthorFromEditorComment variable;\n>>\n>>  - You have \"# Author: \" line that are identical in the result of\n>>    the editor,\n>>\n>> then use that author.  That would allow \"git commit --amend\" to\n>> update a misspelled author name, for example.\n>>\n>> Is that a bit too liberal?  Would it invite mistakes?\n>\n> That does sound pretty good.  And for the specific case of squash,\n> what I would do would be (a) take one of the existing \"Author: \" lines\n> and turn it into an \"# Author:\" line and (b) do the ordinary editing\n> that I do to combine the existing messages?\n>\n> (Maybe my proposed \"detect that they're all the same\" code would run\n> at `merge --squash` time, producing a trailing \"# Author:\" line if all\n> of the produced \"Author: \" lines were identical?)\n\nOr, well, as Peff suggested, maybe SQUASH_MSG should look exactly like\nthe message that rebase's squash gives you, which in fact is a lot\nbetter: no random indent, \"# Author\", etc.  So making your suggested\nchange to parse \"# Author\" in `git commit`, plus a second change to\nmake SQUASH_MSG look like rebase's squash, would achieve my goals.\n\n\n-- \nglasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/\n"},{"id":"256050","messageId":"20150213071041.GA26775@peff.net","threadId":"38548","inReplyTo":"xmqqwq3mogdm.fsf@gitster.dls.corp.google.com","subject":"Re: Keep original author with git merge --squash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-13T07:10:41Z","receivedAt":"2015-02-13T07:10:41Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 12, 2015 at 03:32:37PM -0800, Junio C Hamano wrote:\n\n> > and using \"Author: \" (with no text) does a reset.\n> \n> no (I do not think it is wrong per-se, but I do not think such a\n> good idea).\n\nFair enough. It is probably a minority use case, and one that is likely\nto cause confusion.\n\n> > Also, on the topic of \"merge --squash\". I never use it myself, but\n> > having experimented with it due to this thread, I found the template it\n> > sticks into COMMIT_EDITMSG to be horribly unfriendly for munging. For\n> > example, with two simple commits, I get:\n> [...]\n> I think it should show exactly the same thing as \"rebase -i\" squash\n> insn would give you.  People already know how to munge that, right?\n\nYeah, that was exactly what I expected to see (but didn't). They should\nprobably have the same format, though we may want to enhance both to\ncontain more information (like author names).\n\n> > It also raises a question for the proposal in this thread: if there are\n> > multiple \"Author:\" lines, which one do we take? The first, or the last?\n> \n> I was siding with David's \"pay attention to in-buffer Author: only\n> when all of them agree\".  When squash-merging a branch with two or\n> more authors, we would attribute the authorship silently and\n> automatically to you if you do not do anything special otherwise.\n\nThat's probably reasonable. I was thinking more of a case where you made\nsome fixups on top of somebody else's branch, and then used \"git rebase\n-i\" to squash them together. But I think we already use the authorship\nfor the root of the squash in that case.\n\nThis case collapses nicely if we make a slight tweak to your proposed\nbehavior (or maybe this is what you meant). If there are multiple\nauthors listed, we behave as if none was listed. That would leave the\nauthorship as it behaves today (with the author of the first commit) if\nyou do nothing, or you can override it by dropping all but one.\n\n-Peff\n"},{"id":"256075","messageId":"xmqq1tltobgy.fsf@gitster.dls.corp.google.com","threadId":"38548","inReplyTo":"20150213071041.GA26775@peff.net","subject":"Re: Keep original author with git merge --squash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-13T19:30:53Z","receivedAt":"2015-02-13T19:30:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Thu, Feb 12, 2015 at 03:32:37PM -0800, Junio C Hamano wrote:\n>\n>> > It also raises a question for the proposal in this thread: if there are\n>> > multiple \"Author:\" lines, which one do we take? The first, or the last?\n>> \n>> I was siding with David's \"pay attention to in-buffer Author: only\n>> when all of them agree\".  When squash-merging a branch with two or\n>> more authors, we would attribute the authorship silently and\n>> automatically to you if you do not do anything special otherwise.\n>\n> That's probably reasonable. I was thinking more of a case where you made\n> some fixups on top of somebody else's branch, and then used \"git rebase\n> -i\" to squash them together. But I think we already use the authorship\n> for the root of the squash in that case.\n>\n> This case collapses nicely if we make a slight tweak to your proposed\n> behavior (or maybe this is what you meant). If there are multiple\n> authors listed, we behave as if none was listed. That would leave the\n> authorship as it behaves today (with the author of the first commit) if\n> you do nothing, or you can override it by dropping all but one.\n\nI actually was (and am still) wondering that \"silently ignore all of\nthem if there are multiple ones that contradict with each other\" is\na bad idea, and that was why the last item on the \"possible\nalternatives\" list was to error out and ask clarification.\n"},{"id":"256077","messageId":"20150213195528.GA15107@peff.net","threadId":"38548","inReplyTo":"xmqq1tltobgy.fsf@gitster.dls.corp.google.com","subject":"Re: Keep original author with git merge --squash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-13T19:55:28Z","receivedAt":"2015-02-13T19:55:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 13, 2015 at 11:30:53AM -0800, Junio C Hamano wrote:\n\n> > This case collapses nicely if we make a slight tweak to your proposed\n> > behavior (or maybe this is what you meant). If there are multiple\n> > authors listed, we behave as if none was listed. That would leave the\n> > authorship as it behaves today (with the author of the first commit) if\n> > you do nothing, or you can override it by dropping all but one.\n> \n> I actually was (and am still) wondering that \"silently ignore all of\n> them if there are multiple ones that contradict with each other\" is\n> a bad idea, and that was why the last item on the \"possible\n> alternatives\" list was to error out and ask clarification.\n\nNormally I like \"error out and ask the user\" as an approach to avoiding\nmistakes, but I can think of two bad side effects:\n\n  1. If we pre-populate the \"# Author:\" lines in \"git merge --squash\",\n     then if I run \"git commit\" on the result and don't explicitly take\n     an action to clean up those comment fields, I get an error.  That's\n     kind of annoying.\n\n  2. Dumping the user out of \"git commit\" with an error isn't very\n     elegant. They may have put significant work into writing the commit\n     message. It's saved there in COMMIT_EDITMSG, but what is the easy\n     path to them repeating their action where they left off?\n\nIt seems like the potential for confusion comes from the same place as\nmy complaint (1) above: the implicit-ness of the \"# Author:\" lines (git\nwrites them, assumes you've looked at and manipulated them to your\nliking, and then reads them back in).\n\nWhat if there was a step required of the user to say \"really, I want to\nuse this one\"? Like converting s/Author/Set-Author/, or taking away the\n\"#\" comment character (though that has its own confusions, as you noted\nearlier).\n\n-Peff\n"}]}