oz1cz
oz1cz

Reputation: 5854

Can git automatically store the commit date in a file

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.

Upvotes: 4

Views: 587

Answers (1)

Antonio Petricca
Antonio Petricca

Reputation: 11070

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.

Upvotes: 3

Related Questions