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
  • 58,613
  • 19
  • 146
  • 147
  • You can't commit the file to git if has no change, can you? Or do you consider new files as not changed? – greg0ire Nov 26 '11 at 16:30
  • @greg0ire: Correct. Files which have not changed do not get updated with a new date stamp. –  Nov 26 '11 at 16:48

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.
  • 58,560
  • 8
  • 81
  • 72
greg0ire
  • 22,714
  • 16
  • 72
  • 101
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.
  • 58,560
  • 8
  • 81
  • 72
obmarg
  • 9,369
  • 36
  • 59