In my current project, I am attempting to use git to version control text files that are utilized by software that generates code from them. This in itself isn't a problem, the problem is that every time I generate code, it automatically updates this file with properties such as the date the code was generated, as well as my name.
You can imagine it looking something like this:
SomeHeader{
-SomeProperty : x
-NameOfUserThatGenerateCode: myName
-DateTimeCodeGenerated: 2013-07-23 06:28
-SomeOtherProperty: y
}
What I want, is a way to tell git to say that "it is okay" if both the Name and CodeGeneration time to change (ie: Ignore that there was a change), but DO care if "SomeProperty" changes to say "z".
In that second case, it would commit the entire file (with the updated autogenerated files).
Is there anyway to do that? I recognize that git does changes at the "file" level, but I am hoping that there might be some sort of pre-processing hook that I can tie into that would only work when git attempts to compare file changes.
For those that care, this will enable me to properly version control rhapsody files.
I would recommend:
- keeping a copy of those files (as private files, meaning not versioned): your software would generate code in those copy
- a
clean
script, as a content filter driver, declared in a.gitattributes
file (detailed in Git Pro book).
The idea is for that script to detect, on git add
:
- the content of a 'SomeHeader' property file
- if the copy of that file has changed in way you need to keep (in which case you overwrite the versioned file with the content of that copy)
- if the copy of that file has not changed significantly, in which case, you don't modify the actual property file.
Note that the "keep a copy" part can be automated also by a content filter driver, with a smudge
script activated automatically on git checkout
.
来源:https://stackoverflow.com/questions/17823816/way-to-have-git-only-recognize-a-file-as-changed-if-more-than-a-specific-set-of