{"thread":{"id":"38616","subject":"Identifying user who ran “git reset” command","startedAt":"2015-02-21T04:46:29Z","lastAt":"2015-02-23T18:43:14Z","messageCount":5,"participants":["Technext","Junio C Hamano","Kevin Daudt","Randall S. Becker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"256455","messageId":"1424493989740-7625788.post@n2.nabble.com","threadId":"38616","inReplyTo":null,"subject":"Identifying user who ran “git reset” command","fromName":"Technext","fromEmail":"varuag.chhabra@gmail.com","sentAt":"2015-02-21T04:46:29Z","receivedAt":"2015-02-21T04:46:29Z","isPatch":false,"sender":{"key":"varuag.chhabra@gmail.com","avatar":"https://gravatar.com/avatar/b731428347fdc09c456902cac39c52957f1e296e8edd38f6162400e8402f480e?d=mp&s=160"},"body":"I came across a problem recently. One of the developers committed some\nchanges in a branch. When he checked the branch log (git checkout branch;\ngit log), the commit (say, abc) was showing up but when he checked the log\nfor a file (git log <file_name>), which was part of the given commit (abc),\nthe associated commit (abc) was not showing up; instead, an older commit id\n(say, xyz) was there.\n\nWhen the issue came to my notice, I tried using \"git log --follow\n<file_name>\" to check complete history of a file just to make sure whether\nthe file was renamed to its current name. The output of \"git log --follow\n<file_name>\" was actually showing the commit id (abc) that was missing in\nthe output of \"git log <file_name>\" command. On asking developer whether the\nfile was renamed, i came to know that no renames were done ever for that\nfile. This was confusing and i was stuck because i was not able to figure\nout what happened. Later, it turned out that another developer while pushing\nhis code encountered merge conflict and instead of resolving it, he simply\ndid a \"git reset .\" and the HEAD got shifted.\n\nQ.1) Is there any way i could have figured out about the \"git reset\" command\nthat the other developer executed on his machine? FYI, i have admin access\nto Git.\n\nQ.2) Is there any way we can control such things from happening in future?\nI’m not sure whether this can be controlled using hook because this is not a\n‘push’ command. It's something that's being done just before push. Please\ncorrect me if I’m mistaken. The biggest problem that I see here is that\nevery developer has the rights to commit, which I feel is not right. I feel,\neven restricting it cannot be foolproof but it can certainly bring down such\noccurrences significantly. Any suggestions?\n\n\n\n--\nView this message in context: http://git.661346.n2.nabble.com/Identifying-user-who-ran-git-reset-command-tp7625788.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"256456","messageId":"CAPc5daULfa8oASxvWQ7RuV9T4SXoCw_Pi0EfGkk1GGafa1r9Xg@mail.gmail.com","threadId":"38616","inReplyTo":"1424493989740-7625788.post@n2.nabble.com","subject":"Re: Identifying user who ran “git reset” command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-21T04:58:18Z","receivedAt":"2015-02-21T04:58:18Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"On Fri, Feb 20, 2015 at 8:46 PM, Technext <varuag.chhabra@gmail.com> wrote:\n> The biggest problem that I see here is that\n> every developer has the rights to commit, which I feel is not right.\n\nHmm, if you have some way to classify developers into two (or more?)\ncategories, what would you do instead? Allow some to commit, and\nwhat can others do? Show their change to more senior people and\nask them to commit?\n\nThat is more or less in a traditional centralized SCM set-up, I think.\n\nWith Git, you can do something similar with \"rights to push\", if you\nprefer such a workflow. It would go like this:\n\n (1) Everybody can commit to their own repository and grow their own\n      history. What you want to protect is the shared view of the project\n      history, and restricting what people can do in their own playpen is\n      unnecessary.\n\n (2) Senior people can push into the project's central repository, just\n      like in the set-up you currently have.\n\n (3) Junior people can ask senior people to pull from them. Senior\n      people will pull their changes, review, and if the changes are\n      good, merge them and push the result to the project's central\n      repository. Alternatively, junior people can do this asking by\n      sending patches to senior people, who will review and then\n      apply to their tree and push the result out to the common history.\n"},{"id":"256458","messageId":"1424495778228-7625791.post@n2.nabble.com","threadId":"38616","inReplyTo":"CAPc5daULfa8oASxvWQ7RuV9T4SXoCw_Pi0EfGkk1GGafa1r9Xg@mail.gmail.com","subject":"Re: Identifying user who ran “git reset” command","fromName":"Technext","fromEmail":"varuag.chhabra@gmail.com","sentAt":"2015-02-21T05:16:18Z","receivedAt":"2015-02-21T05:16:18Z","isPatch":false,"sender":{"key":"varuag.chhabra@gmail.com","avatar":"https://gravatar.com/avatar/b731428347fdc09c456902cac39c52957f1e296e8edd38f6162400e8402f480e?d=mp&s=160"},"body":"Thanks Junio for the prompt reply! :) Yes, that's exactly how i would like\nthings to be. I'll definitely try to push this thing and see if this flow\ncan be implemented.\n\nHowever, can you please guide me whether there's any way i could have\nfigured out about the git reset command that the developer executed on his\nlocal? (my first query)\n\nAlso, am i right in thinking that a check cannot be implemented using hooks\nor any other similar way? (my second query)\n\n\n\n--\nView this message in context: http://git.661346.n2.nabble.com/Identifying-user-who-ran-git-reset-command-tp7625788p7625791.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"256521","messageId":"20150223164833.GA17528@vps892.directvps.nl","threadId":"38616","inReplyTo":"1424495778228-7625791.post@n2.nabble.com","subject":"Re: Identifying user who ran “git reset” command","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2015-02-23T16:48:33Z","receivedAt":"2015-02-23T16:48:33Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Fri, Feb 20, 2015 at 10:16:18PM -0700, Technext wrote:\n> Thanks Junio for the prompt reply! :) Yes, that's exactly how i would like\n> things to be. I'll definitely try to push this thing and see if this flow\n> can be implemented.\n> \n> However, can you please guide me whether there's any way i could have\n> figured out about the git reset command that the developer executed on his\n> local? (my first query)\n\ngit reset . is just a local working tree operation, which does not leave\nsomething behind, just like when the user would do any other file\noperations and comitted that. This created a so called evil merge, which\nare not easy to detect (see [1] for some possible solutions)\n\n> \n> Also, am i right in thinking that a check cannot be implemented using hooks\n> or any other similar way? (my second query)\n\nBecause an evil merge is hard to detect, it's even harder to do it\nautomated in a script. Human review works much better for this (when\nmerging in the changes from the developer).\n\n\n[1]: https://stackoverflow.com/a/27744011/20261\n"},{"id":"256529","messageId":"00e601d04f98$95177470$bf465d50$@nexbridge.com","threadId":"38616","inReplyTo":"20150223164833.GA17528@vps892.directvps.nl","subject":"RE: Identifying user who ran \"git reset\" command","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2015-02-23T18:43:14Z","receivedAt":"2015-02-23T18:43:14Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On 23 Feb 2015, Kevin Daudt wrote:\n> On Fri, Feb 20, 2015 at 10:16:18PM -0700, Technext wrote:\n> > Thanks Junio for the prompt reply! :) Yes, that's exactly how i would\n> > like things to be. I'll definitely try to push this thing and see if\n> > this flow can be implemented.\n> > However, can you please guide me whether there's any way i could have\n> > figured out about the git reset command that the developer executed on\n> > his local? (my first query)\n> \n> git reset . is just a local working tree operation, which does not leave\n> something behind, just like when the user would do any other file\noperations\n> and comitted that. This created a so called evil merge, which are not easy\nto\n> detect (see [1] for some possible solutions)\n> \n> >\n> > Also, am i right in thinking that a check cannot be implemented using\n> > hooks or any other similar way? (my second query)\n> \n> Because an evil merge is hard to detect, it's even harder to do it\nautomated in a\n> script. Human review works much better for this (when merging in the\nchanges\n> from the developer).\n\nThe only effective way I have found to deal with this is to have an\nimplemented policy of making sure that developers only push changes to topic\nbranches and have an approver handle the merge. This will not eliminate the\nevil merge or reset, but at least you get a second set of eyes on it. With\nthat said, the oops merge or reset is different, which an accidental\noperation.\n\nI know it is off-topic, but there is an approach used by other systems (some\ncode-management, some not) that implement per-command policies. Something\nlike a client-side hook or config-like access control list may be useful:\nlike a hooks/pre-execute (invoked possibly as high up as in run_argv() after\nhandle_options()) that gets passed argv, and is able to accept/decline the\ncommand, might catch accidents. Granted this slows things down a whole lot,\nbut places that use (I didn't say need) command-level restrictions, often\nare willing to accept performance degradation and the resulting grumbling\nthat comes with it. And you've probably had this discussion before, so I\nsincerely apologize in advance for bringing it up.\n\nCheers,\nRandall\n\n-- Brief whoami: NonStop&UNIX developer since approximately\nUNIX(421664400)/NonStop(211288444200000000)\n-- In real life, I talk too much.\n"}]}