It can be surprisingly hairy to have such an obvious source of merge conflicts in your repo,
and it is very easy to extract the info from git while you browse your repo (git log -1 the/file).
Before digging into how to actually store that info in the file's content,
perhaps you could settle for a handy shell shortcut, or for an outline integrated to your editor ? vscode for example has the git lens extension which gives you something pretty close (per line annotations, actually)
The creation date would be pretty static, so it could be inserted at a file's creation and kept that way ;
for the other parts of the header : I think a filter would be the closest to the right way to do it
Official docs here : gitattributes
See an explanation in this SO answer : Can git filter out certain lines before commit?
You would write two scripts :
- one, the cleanscript, would replace the header lines with constant values (eg :# Last Modified :with no date)
- the second, the smudgescript, would rungit log -1and fill the lines with the desired values
The clean script will be run when staging a file, and would make sure that the blobs stored in git have a constant header, to avoid problems when merging, rebasing, etc
The smudge script will be run when checking out a file, and will write the correct content in the worktree version -- the file on disk, which you would actually open in your editor.
The main point not sorted in this answer is : the smudge script receives the file's content on stdin, not the file's name, so I don't see a clean way to run git log -1 file/name from that script yet.