Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can git automatically store the commit date in a file

Tags:

git

I have a number of text files under git control. The files include a line of text such as this:

Date of this revision: 23.05.2021

Is it possible to make git update this automatically whenever the file is committed? I know it can be done in version control systems such as RCS, but I haven't been able to find a way to do it in git.

like image 703
oz1cz Avatar asked Oct 23 '25 05:10

oz1cz


1 Answers

I think that a solution may be to write a git client hook by writing an pre-commit hook in order to:

  1. Get the list of changed files.
  2. Search for your header comments to update.
  3. Stage again the updated file(s).
  4. Return a success by the hook in order to perform the commit.

The nasty thing is that you have to create a template on each developer machine to initialize the repo with the hook(s) at each git clone.

Here https://www.omerkatz.com/blog/2013/5/23/git-hooks-part-2-implementing-git-hooks-using-python you can find a lot of information about writing and managing hooks.

like image 91
Antonio Petricca Avatar answered Oct 25 '25 19:10

Antonio Petricca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!