I am working on task in which I need the git commit date to be written into one of the files being committed. I need it to happen in a couple of scenarios:
- While branch was pushed it into remote repo
- While merging it into master
Specifically, the change should look like this:
Before commit: private String DATE="$DATE$"
After commit: private String DATE="$DATE: 2020-05-08 18:19:25 $"
Here's what I've tried so far:
I have followed https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#Keyword-Expansion and added .gitattributes, .gitconfig, .git_filters(which has smudge and clean filter) into my project.
Below are the things which i configured in proj:
- .gitConfig:
clean = .git_filters/dater.clean
smudge = .git_filters/dater.smudge %f
- .gitAttributes:
*.java filter=dater
- .git_filters: (created separate folder under parent repo)
dater.clean:
#!/usr/bin/sh
sed s/$Date$/`date +%Y%m%d`/g
dater.smudge:
#! /usr/bin/env ruby
data = STDIN.read
last_date = `git log --pretty=format:"%ad" -1`
puts data.gsub('$Date$', '$Date: ' + last_date.to_s + '$')
When i tried with the above configuration.. it doesn't work..Looking for help to fix this issue plz...