I'm trying to find the last modification timestamp of a file in a Git repository. I understand that Git doesn't preserve timestamps for files under its control, so some trickery is due.
For purposes of discussion, consider the following directory structure:
/ ├─ catalog.xml ├─+ doc │ └─ notes.md └─+ src ├─ index.xhtml └─ style.css What I'm trying to accomplish is this: Whenever changes are about to be committed,
- if any file under the
srcdirectory was modified,- find the most recent (filesystem) modification timestamp,
- update the
catalog.xmlmanifest using that timestamp.
How can this be done?
If a potential solution requires scripting, I'm looking for something that works on Windows, using batch and/or PowerShell as the scripting environment.
Additional details:
As far as I understand, Git doesn't record modification timestamps for individual files. While commit objects are timestamped, this isn't useful for my needs. Are per-file modification timestamps perhaps stored in the local "index"?
Either way, I will have to tap into Git's processing pipeline. A pre-commit hook seems like a reasonable callback to gather the information and perform the update. This isn't ideal, however, as it may result in changing a file. Could a "clean" filter be used for this instead?
catalog.xmlcould end up being massive. Also, how will you handle multiple clones of the same repo? You'll likely end up with large conflicts.catalog.xmlhave two different changes for the same file that couldn't be auto-merged. For every file changed at both H1 and H2 there will be a conflict. When you resolve the conflicts you find thatcatalog.xmllies because files insrcchanged by merge butcatalog.xmldoesn't get it.