0

I need to inject Git information at the top of each source code that is a part of Git repository. In past, we have worked on CVS repository for maintaining source code. In CVS, CVS information was added at the top of the source file with each commit.

##########################################
#              CVS information
#
#    $Source: /cvs_repo/test/prog1.pl,v $
#    $Revision: 1.4 $
#    $Date: 2020/06/22 10:15:00 $
#    $Author: ma $
#########################################

Is it possible to add such information in Git also with each commit? Please suggest.

Thanks

Manoj Agarwal
  • 365
  • 2
  • 17
  • 2
    Here's [one old question about this](https://stackoverflow.com/q/11534655), with 'possible duplicate' links to a few more. I don't know which one is the canonical one. – Rup Jun 22 '20 at 11:00
  • 2
    The only built in support is for clean and smudge filters which can do stuff like that, but those will only change the files in your work tree, the committed files will either not have any of that, or they will have a template that the smudge filter would modify. Can I ask why you *need* to do this? What is the problem you're trying to solve where this information is the solution? Perhaps there are other/better ways. – Lasse V. Karlsen Jun 22 '20 at 11:15
  • 1
    Note that no matter what you do, if you want information to be added inside the files part of your repository, you will not be able to add the commit hash into the header of the files. – Lasse V. Karlsen Jun 22 '20 at 11:15
  • @LasseV.Karlsen "*you will not be able to add the commit hash*" You're able with [`ident` in `.gitattributes`](https://git-scm.com/docs/gitattributes#_ident). – phd Jun 22 '20 at 12:24
  • 1
    I wasn't very clear, I meant that in the committed file, not the work tree file. In the committed blob, you will not be able to get the file hash or the commit hash. Unless you use the SHAttered vulnerability. This means that sites such as GitHub which browse the contents of your repository, will not be able to show those things in-place, unless they do similar replace-on-show type of magic. – Lasse V. Karlsen Jun 22 '20 at 12:27

0 Answers0