0

I came across a problem recently. One of the developers committed some changes in a branch. When he checked the branch log (git checkout branch; git log), the commit (say, abc) was showing up but when he checked the log for a file (git log <file_name>), which was part of the given commit (abc), the associated commit (abc) was not showing up; instead, an older commit id (say, xyz) was there.

When the issue came to my notice, I tried using git log --follow <file_name> to check complete history of a file just to make sure whether the file was renamed to its current name. The output of git log --follow <file_name> was actually showing the commit id (abc) that was missing in the output of git log <file_name> command. On asking developer whether the file was renamed, i came to know that no renames were done ever for that file. This was confusing and i was stuck because i was not able to figure out what happened. Later, it turned out that another developer while pushing his code encountered merge conflict and instead of resolving it, he simply did a git reset . and the HEAD got shifted.

Q.1) Is there any way i could have figured out about the git reset command that the other developer executed on his machine? FYI, i have admin access to Git.

Q.2) Is there any way we can control such things from happening in future? I’m not sure whether this can be controlled using hook because this is not a ‘push’ command. It's something that's being done just before push. Please correct me if I’m mistaken. The biggest problem that I see here is that every developer has the rights to commit, which I feel is not right. I feel, even restricting it cannot be foolproof but it can certainly bring down such occurrences significantly. Any suggestions?

Technext
  • 7,887
  • 9
  • 48
  • 76
  • You mean that every developer commits in the repo rather than pushing to it from their local repo? – Martin G Feb 20 '15 at 10:19
  • No, they request for rights to push and we grant them the same. Issue is that we do not pose restrictions on who all are allowed to push. As long as the person who is pushing the code has a valid JIRA associated, they can push it to a repo. – Technext Feb 20 '15 at 11:24

0 Answers0