1

Years ago, I used to work with a version control software that used to automatically add authors and the first line of the commit at the top of the source code. He found this very useful to quickly check the history without having to search through the commits. I'm wondering if this is possible with Git (right now, because of some external requirements, we at least need the authors of the file to be added into the file itself). I looked into git hooks but could not find anything so far in the post commit script. Our repositories are hosted on Bitbucket.

Since I have not been able to find anything so far, I'm wondering if this is even possible to be achieved and if so where can I start looking? Obviously if there is an open source script that does this, it would be the best.

Thanks for any pointers!

Ramana
  • 243
  • 4
  • 15
  • 1
    You can ammend a commit in a post-commit hook. – Jaa-c Aug 24 '18 at 10:03
  • 1
    Probably you can do so with a pre-commit hook... a post commit seems difficult, because you need to do another commit to save the adds – ErniBrown Aug 24 '18 at 10:18
  • 1
    This is not exactly a duplicate (or maybe it is): https://stackoverflow.com/questions/16524225/how-can-i-populate-the-git-commit-id-into-a-file-when-i-commit – Jim Stewart Aug 24 '18 at 12:57

1 Answers1

1

There are a couple of problems in doing what you want to. If you want to modify a file during a commit you can do so in the pre-commit hook. But at this particular moment your commit message does not exist, so you cannot add it to the file. You can only add author name, via a script that checks the first line against the config. Maybe another option is to reverse this, prepare the commit message based on the first line of the file, writing a prepare-commit-msg or a commit-msg hook.

ErniBrown
  • 1,283
  • 12
  • 25
  • Thank you. At least I will be able to add the name of the author in the source code. I will look into the documentation of the prepare commit message hook also. Marking your answer as resolving the query. Thank you – Ramana Aug 25 '18 at 04:13