4

Say I have a file like the following:

/**
 * A Test class
 * @version 2011.11.24
 */
public class Test
{

}

I would like to have the date stamp automatically updated each time it gets committed to git and there has been a change in the file. Is this possible?

pb2q
  • 56,563
  • 18
  • 143
  • 144
Tim Cooper
  • 151,519
  • 37
  • 317
  • 271

2 Answers2

1

You could write a clean filter. This would actually occur when you add the files to the staging area, which could be even better (because to could see the result without commiting it).

Clean and smudge filters are described here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion. This page also contains an example of keyword expansion for $Date$, using a small ruby script.

ax.
  • 56,201
  • 7
  • 77
  • 69
greg0ire
  • 22,009
  • 15
  • 69
  • 96
0

You could write a simple script to automatically scan all your source files and update the dates, then have it run before each commit using the pre-commit hook. More information on git's hooks can be found here

ax.
  • 56,201
  • 7
  • 77
  • 69
obmarg
  • 9,159
  • 34
  • 58