{"thread":{"id":"50878","subject":"\"commit --author=...\" does not work if global email and name is not set","startedAt":"2019-04-05T07:34:52Z","lastAt":"2019-04-09T07:43:39Z","messageCount":10,"participants":["Piotr Krukowiecki","Junio C Hamano","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"373185","messageId":"CAA01Csp7y9=2n9=TNYMMw9LUO_cENz7FBeZjFrUd2FvHFT9NCQ@mail.gmail.com","threadId":"50878","inReplyTo":null,"subject":"\"commit --author=...\" does not work if global email and name is not set","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2019-04-05T07:34:39Z","receivedAt":"2019-04-05T07:34:52Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"Hi,\n\nI have a repo downloaded on machines which do automatic tests.\nSometimes I want to make a quick fix there and push back to origin.\nReading git-commit docs I had impression that I can use \"--author=me\"\nand it will work. But it requires setting global user name and email:\n\n========================================================\n$ git commit --author=pkruk\n\n*** Please tell me who you are.\n\nRun\n\n  git config --global user.email \"you@example.com\"\n  git config --global user.name \"Your Name\"\n\nto set your account's default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: unable to auto-detect email address (got 'some@default.(none)')\n========================================================\n\nI do not want to set the default name/email, because I want commits to\nhave real names, and not some \"automatic test account\" info. For\npushing back to origin I already have to use a read-write SSH key, but\nlack of default name/email would prevent accidental commits (people\nWILL forget to use --author ...).\n\nDo you think changing git to not require default name/email if\n\"--author\" is specified is possible (and hopefully easy and quick to\nimplement ;))?\n\nThanks,\n\n-- \nPiotr Krukowiecki\n"},{"id":"373187","messageId":"CAPc5daVQTouBVqJPccQNdzFP6XYEL7G2UUH-HC4QgYdRWt__Kw@mail.gmail.com","threadId":"50878","inReplyTo":"CAA01Csp7y9=2n9=TNYMMw9LUO_cENz7FBeZjFrUd2FvHFT9NCQ@mail.gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-05T08:11:48Z","receivedAt":"2019-04-05T08:12:03Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"On Fri, Apr 5, 2019 at 4:35 PM Piotr Krukowiecki\n<piotr.krukowiecki@gmail.com> wrote:\n>\n> Hi,\n>\n> I have a repo downloaded on machines which do automatic tests.\n> Sometimes I want to make a quick fix there and push back to origin.\n> Reading git-commit docs I had impression that I can use \"--author=me\"\n> and it will work. But it requires setting global user name and email:\n\nYou can still do\n\n git -c user.name=me -c user.email=me@my.addre.ss commit ...\n\nif you do not want to follow the advice message to store the ident\npermanently.\n\n>   git config --global user.email \"you@example.com\"\n>   git config --global user.name \"Your Name\"\n\nTechnically, what you are missing when you give --author is only\nthe committer ident, so you can probably use\n\n  GIT_COMMITTER_NAME=me GIT_COMMITTER_EMAIL=me@my.addre.ss \\\n  git commit --author=me ...\n\neven though it is not any shorter ;-).\n\nI think all of the above is quite expected. The fact that --author is used to\nspecify the ident of the author is a good sign that it is different from the\ncommitter ident (otherwise the user would be using a configured default\nident that is always used as the committer ident, without overriding it\nwith the --author) option.\n"},{"id":"373333","messageId":"8636mvng8n.fsf@gmail.com","threadId":"50878","inReplyTo":"CAA01Csp7y9=2n9=TNYMMw9LUO_cENz7FBeZjFrUd2FvHFT9NCQ@mail.gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2019-04-06T18:25:12Z","receivedAt":"2019-04-06T18:25:20Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n\n> Hi,\n>\n> I have a repo downloaded on machines which do automatic tests.\n> Sometimes I want to make a quick fix there and push back to origin.\n> Reading git-commit docs I had impression that I can use \"--author=me\"\n> and it will work. But it requires setting global user name and email:\n>\n> ========================================================\n> $ git commit --author=pkruk\n>\n> *** Please tell me who you are.\n>\n> Run\n>\n>   git config --global user.email \"you@example.com\"\n>   git config --global user.name \"Your Name\"\n>\n> to set your account's default identity.\n> Omit --global to set the identity only in this repository.\n>\n> fatal: unable to auto-detect email address (got 'some@default.(none)')\n> ========================================================\n>\n> I do not want to set the default name/email, because I want commits to\n> have real names, and not some \"automatic test account\" info. For\n> pushing back to origin I already have to use a read-write SSH key, but\n> lack of default name/email would prevent accidental commits (people\n> WILL forget to use --author ...).\n>\n> Do you think changing git to not require default name/email if\n> \"--author\" is specified is possible (and hopefully easy and quick to\n> implement ;))?\n\nAs Junio said, the \"--author=<author name and email>\" sets the author\nidentity, but not the committer identity; you can work around the issue\nwith \"git -c user.name=me -c user.email=me@email.my\".\n\nIn Git the commit stories both the author and the committer.  The author\nis the person who made the changes, the committer is the person who\nentered the changes into repository (created a commit object).  You\nmight want to enter into your repository changes made by somebody else\n(that you for example got as a patch): that is what --author is for.\n\nBetter though is to focus on what you want, namely to prevent accidental\ncommits without specified author, instead of how you want to achieve it,\ni.e. using --author to provide both author and committer identity (the\nXY problem).  On that machine with \"automatic test account\" set up\npre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT\nenvironment variable is not the \"automatic test account\".\n\nHope that helps,\n--\nJakub Narębski\n"},{"id":"373401","messageId":"xmqq36mt9e7l.fsf@gitster-ct.c.googlers.com","threadId":"50878","inReplyTo":"8636mvng8n.fsf@gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-08T06:57:18Z","receivedAt":"2019-04-08T06:57:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> As Junio said, the \"--author=<author name and email>\" sets the author\n> identity, but not the committer identity; you can work around the issue\n> with \"git -c user.name=me -c user.email=me@email.my\".\n\nHaving slept on this a bit, I am of two minds here.\n\nIt certainly is possible to change the rule to say that committer\nidentity, when not set at all, takes the default from the author\nidentity, if and only if the latter is explicitly given, and that\nwould certainly make it work as Piotr wanted to.\n\nBut then, that is only valid if the users use --author with the\nauthor make that refers to self every time s/he makes a commit.  I\nam not sure if that is a plausible use case.  The command line\noption \"--author\" is really meant to be used one-off to name\nsomebody other than self in a rare occasion.  Use of --author that\nbreaks the built-in safety of committing under undesired identity\n(e.g. \"<user@localhost>\") without realizing before the mistake is\nburied deep in the history may not be such a goodidea.\n\n> Better though is to focus on what you want, namely to prevent accidental\n> commits without specified author, instead of how you want to achieve it,\n> i.e. using --author to provide both author and committer identity (the\n> XY problem).  On that machine with \"automatic test account\" set up\n> pre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT\n> environment variable is not the \"automatic test account\".\n\nIt could be s/is not/is/ perhaps, but I do like the line of\nreasoning and where it leads us.  \"To prevent mistakes\" is something\nhooks are good for.\n\nThanks.\n"},{"id":"373407","messageId":"CAA01CsqAt8osKArhdgATNj29+a9VO6wUwhX6=cRebnDBFx_EVg@mail.gmail.com","threadId":"50878","inReplyTo":"xmqq36mt9e7l.fsf@gitster-ct.c.googlers.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2019-04-08T09:54:29Z","receivedAt":"2019-04-08T09:54:43Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Fri, Apr 5, 2019 at 10:12 AM Junio C Hamano <gitster@pobox.com> wrote:\n> You can still do\n>\n>  git -c user.name=me -c user.email=me@my.addre.ss commit ...\n[...]\n>   GIT_COMMITTER_NAME=me GIT_COMMITTER_EMAIL=me@my.addre.ss \\\n>   git commit --author=me ...\n>\n> even though it is not any shorter ;-).\n\nThere are a couple of problems with this approach:\n\n1. it's long, as you mentioned\n2. it's easy to make a mistake - misspell name or address\n3. you need to remember the options/variable names (\"-c\", user.name\nor GIT_COMMITER_NAME etc) - it's not user friendly\n\nIf you make a mistake you end up with two different identities in\nhistory. Then e.g. searching for an author might not find all commits.\n\n\nOn Mon, Apr 8, 2019 at 8:57 AM Junio C Hamano <gitster@pobox.com> wrote:\n> Having slept on this a bit, I am of two minds here.\n>\n> It certainly is possible to change the rule to say that committer\n> identity, when not set at all, takes the default from the author\n> identity, if and only if the latter is explicitly given, and that\n> would certainly make it work as Piotr wanted to.\n\nYes it would. But I understand your arguments too.\n\nMaybe instead of changing how \"--author\" works, we could add\n\"--commiter\" which works the same but for commiter, that is searches\nfor committer in history? Then I could do \"git commit --commiter=me\".\n\nOn the other hand this makes commiter somehow more important than\nauthor. The \"author\" is more obvious to users I think. When both\nauthor and commiter are the same, git shows the author only. In svn\n(and I think also in mercurial) there is only \"author\".\nSo the first thought for users is \"I should set the author\", I\nbelieve. At least it was like that for me. From this point of view, I\nthink the author should be more important. So I would prefer to be\nable to use \"git commit --author=me\" and have it work, instead of\nusing \"--commiter\" which I believe is an implementation detail... I\ndon't want to set the commiter, I want to set the author of the\ncommit.\n\nSo another possibility: add \"--user=me\" which would set both(?) author\nand commiter. I don't like that we would add another \"idiom\"\n(\"author\", \"commiter\", and now \"user\") but OTOH we already have\n\"user.name\" and \"user.email\" configuration names.\n\n\n> On Sat, Apr 6, 2019 at 8:25 PM Jakub Narebski <jnareb@gmail.com> wrote:\n> > Better though is to focus on what you want, namely to prevent accidental\n> > commits without specified author, instead of how you want to achieve it,\n> > i.e. using --author to provide both author and committer identity (the\n> > XY problem).  On that machine with \"automatic test account\" set up\n> > pre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT\n> > environment variable is not the \"automatic test account\".\n\nI'm not sure if I follow you. I want to be able to make both \"real\nuser\" and \"automatic test account user\" commits from that machine. I\nwant to make sure that:\n- automatic commits (scripts) use their own account\n- real person making commit uses their own account\n\nIMO the only way this can be achieved is by not having any default\naccount setup, so that both the scripts and the real users need to\nspecify it \"by hand\".\n\n\n-- \nPiotr Krukowiecki\n"},{"id":"373413","messageId":"86y34kn4c8.fsf@gmail.com","threadId":"50878","inReplyTo":"CAA01CsqAt8osKArhdgATNj29+a9VO6wUwhX6=cRebnDBFx_EVg@mail.gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2019-04-08T11:06:47Z","receivedAt":"2019-04-08T11:06:55Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n\n>> On Sat, Apr 6, 2019 at 8:25 PM Jakub Narebski <jnareb@gmail.com> wrote:\n>>>\n>>> Better though is to focus on what you want, namely to prevent accidental\n>>> commits without specified author, instead of how you want to achieve it,\n>>> i.e. using --author to provide both author and committer identity (the\n>>> XY problem).  On that machine with \"automatic test account\" set up\n>>> pre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT\n>>> environment variable is not the \"automatic test account\".\n>\n> I'm not sure if I follow you. I want to be able to make both \"real\n> user\" and \"automatic test account user\" commits from that machine. I\n> want to make sure that:\n> - automatic commits (scripts) use their own account\n> - real person making commit uses their own account\n>\n> IMO the only way this can be achieved is by not having any default\n> account setup, so that both the scripts and the real users need to\n> specify it \"by hand\".\n\nIf a real person making commits uses their own account (just on that\nmachine), he or she can set up `user.name` and `user.email` settings in\nthe per-user Git configuration file with\n\n  $ git config --global user.name  \"My Name\"\n  $ git config --global user.email me@my.email.com\n\nIf however one is doing commits from the \"automatic test user\" account,\nthen the `pre-commit` or `commit-msg` hook configured for that specific\nrepository for that automatic account would be run, which can detect\nthat the commit was not done with\n\n  $ git commit --author=\"My Name <me@my.email.com>\"\n\nThe additional advantage is that you can examine committer data to\ndetect such cases of committing out of automatic account.\n\nI hope that helps,\n--\nJakub Narębski\n"},{"id":"373416","messageId":"CAA01CspJAPnBFsQsXP4Dpweeg6oBVj==TB0aEnK5o1Et5zS30Q@mail.gmail.com","threadId":"50878","inReplyTo":"86y34kn4c8.fsf@gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2019-04-08T11:55:25Z","receivedAt":"2019-04-08T11:55:58Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Mon, Apr 8, 2019 at 1:06 PM Jakub Narebski <jnareb@gmail.com> wrote:\n>\n> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n>\n> >> On Sat, Apr 6, 2019 at 8:25 PM Jakub Narebski <jnareb@gmail.com> wrote:\n> >>>\n> >>> Better though is to focus on what you want, namely to prevent accidental\n> >>> commits without specified author, instead of how you want to achieve it,\n> >>> i.e. using --author to provide both author and committer identity (the\n> >>> XY problem).  On that machine with \"automatic test account\" set up\n> >>> pre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT\n> >>> environment variable is not the \"automatic test account\".\n> >\n> > I'm not sure if I follow you. I want to be able to make both \"real\n> > user\" and \"automatic test account user\" commits from that machine. I\n> > want to make sure that:\n> > - automatic commits (scripts) use their own account\n> > - real person making commit uses their own account\n> >\n> > IMO the only way this can be achieved is by not having any default\n> > account setup, so that both the scripts and the real users need to\n> > specify it \"by hand\".\n>\n> If a real person making commits uses their own account (just on that\n> machine), he or she can set up `user.name` and `user.email` settings in\n> the per-user Git configuration file\n\nThere is one common \"test\" (Windows) account which is used both by\nautomatic test scripts and by real people who log into that machine,\nso this is not possible.\n\n\n> If however one is doing commits from the \"automatic test user\" account,\n> then the `pre-commit` or `commit-msg` hook configured for that specific\n> repository for that automatic account would be run, which can detect\n> that the commit was not done with\n>\n>   $ git commit --author=\"My Name <me@my.email.com>\"\n>\n> The additional advantage is that you can examine committer data to\n> detect such cases of committing out of automatic account.\n\nDo you mean following?\n\n1. set default user (user.name, user.email) to \"automatic test user\"\non that machine\n2. set commit hook to prevent commits with \"automatic test user\" AUTHOR\n3. scripts will set AUTHOR (--author) to for example \"script X\" or\n\"automatic script user\" - different than the default user\n4. real users will set AUTHOR to their own identity (--author=me)\n\nI suppose that would work. Looks much more complicated than simply\nsetting \"--author\" (or \"--user\") though...\n\n\n-- \nPiotr Krukowiecki\n"},{"id":"373458","messageId":"xmqq7ec38zam.fsf@gitster-ct.c.googlers.com","threadId":"50878","inReplyTo":"CAA01CspJAPnBFsQsXP4Dpweeg6oBVj==TB0aEnK5o1Et5zS30Q@mail.gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-09T06:31:45Z","receivedAt":"2019-04-09T06:31:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n\n>> If a real person making commits uses their own account (just on that\n>> machine), he or she can set up `user.name` and `user.email` settings in\n>> the per-user Git configuration file\n>\n> There is one common \"test\" (Windows) account which is used both by\n> automatic test scripts and by real people who log into that machine,\n> so this is not possible.\n> ...\n> Do you mean following?\n>\n> 1. set default user (user.name, user.email) to \"automatic test user\"\n> on that machine\n> 2. set commit hook to prevent commits with \"automatic test user\" AUTHOR\n> 3. scripts will set AUTHOR (--author) to for example \"script X\" or\n> \"automatic script user\" - different than the default user\n> 4. real users will set AUTHOR to their own identity (--author=me)\n\nI do not think 4. is what Jakub meant, which is to make the author\nand committer identity for real humans come from the configuration\nthat becomes in effect automatically by merely logging in.\n\nIf that cannot be arranged, something like 4. may have to serve as a\nrough approximation; that sound like the best you could do under\nthat limitation without breaking the general usability of the\nsystem.\n"},{"id":"373461","messageId":"CAA01CsrO8NyzG8zfRY3=k5T2EvPJvJzMrfBgH19=ib-x69mEQg@mail.gmail.com","threadId":"50878","inReplyTo":"xmqq7ec38zam.fsf@gitster-ct.c.googlers.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2019-04-09T07:03:12Z","receivedAt":"2019-04-09T07:03:28Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Tue, Apr 9, 2019 at 8:31 AM Junio C Hamano <gitster@pobox.com> wrote:\n> I do not think 4. is what Jakub meant, which is to make the author\n> and committer identity for real humans come from the configuration\n> that becomes in effect automatically by merely logging in.\n\nUnfortunately this is not possible\n\n\n> If that cannot be arranged, something like 4. may have to serve as a\n> rough approximation; that sound like the best you could do under\n> that limitation without breaking the general usability of the\n> system.\n\nWhat do you think about my \"--user\" idea?\n\n\n-- \nPiotr Krukowiecki\n"},{"id":"373463","messageId":"86tvf7mxni.fsf@gmail.com","threadId":"50878","inReplyTo":"CAA01CspJAPnBFsQsXP4Dpweeg6oBVj==TB0aEnK5o1Et5zS30Q@mail.gmail.com","subject":"Re: \"commit --author=...\" does not work if global email and name is not set","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2019-04-09T07:43:29Z","receivedAt":"2019-04-09T07:43:39Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n> On Mon, Apr 8, 2019 at 1:06 PM Jakub Narebski <jnareb@gmail.com> wrote:\n>> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n>>>> On Sat, Apr 6, 2019 at 8:25 PM Jakub Narebski <jnareb@gmail.com> wrote:\n>>>>>\n>>>>> Better though is to focus on what you want, namely to prevent accidental\n>>>>> commits without specified author, instead of how you want to achieve it,\n>>>>> i.e. using --author to provide both author and committer identity (the\n>>>>> XY problem).  On that machine with \"automatic test account\" set up\n>>>>> pre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT\n>>>>> environment variable is not the \"automatic test account\".\n>>>\n>>> I'm not sure if I follow you. I want to be able to make both \"real\n>>> user\" and \"automatic test account user\" commits from that machine. I\n>>> want to make sure that:\n>>> - automatic commits (scripts) use their own account\n>>> - real person making commit uses their own account\n>>>\n>>> IMO the only way this can be achieved is by not having any default\n>>> account setup, so that both the scripts and the real users need to\n>>> specify it \"by hand\".\n>>\n>> If a real person making commits uses their own account (just on that\n>> machine), he or she can set up `user.name` and `user.email` settings in\n>> the per-user Git configuration file\n>\n> There is one common \"test\" (Windows) account which is used both by\n> automatic test scripts and by real people who log into that machine,\n> so this is not possible.\n\nWell, if it is not possible to make it multi-account machine, where\neverybody logins with their own account...\n\n>> If however one is doing commits from the \"automatic test user\" account,\n>> then the `pre-commit` or `commit-msg` hook configured for that specific\n>> repository for that automatic account would be run, which can detect\n>> that the commit was not done with\n>>\n>>   $ git commit --author=\"My Name <me@my.email.com>\"\n>>\n>> The additional advantage is that you can examine committer data to\n>> detect such cases of committing out of automatic account.\n>\n> Do you mean following?\n>\n> 1. set default user (user.name, user.email) to \"automatic test user\"\n> on that machine\n> 2. set commit hook to prevent commits with \"automatic test user\" AUTHOR\n> 3. scripts will set AUTHOR (--author) to for example \"script X\" or\n> \"automatic script user\" - different than the default user\n\nOr, if possible, you could simply check if `git commit` was called from\na login shell / interactive shell, rather than from a script.  This\nwould make all scripts work automatically without any changes.\n\nAlternatively scripts could set some special environment variable that\nwould be checked by the commit hook.\n\n> 4. real users will set AUTHOR to their own identity (--author=me)\n>\n> I suppose that would work. Looks much more complicated than simply\n> setting \"--author\" (or \"--user\") though...\n\nhowever, it is one-time configuration.\n\nYet another solution would be for each user to create his or her own\nclone of repository (sharing repository data using `git clone\n--reference`), and set up their identities in per-repository\nconfiguration.  Though that requires them to use the correct\ndirectory...\n\nBest,\n--\nJakub Narębski\n"}]}