3

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.

Aerophilic
  • 885
  • 2
  • 9
  • 22
  • someone already asked that: http://stackoverflow.com/questions/12382447/can-git-ignore-specific-lines-matching-a-pattern – Udy Jul 24 '13 at 06:49
  • I had saw that stackoverflow article... it doesn't quite do what I want as I can't get rid of the "special" properties. I am going to be trying VonC's response to see if that might work. – Aerophilic Jul 24 '13 at 16:58

1 Answers1

3

I would recommend:

http://git-scm.com/figures/18333fig0703-tn.png

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thinking it through, while I think this approach may work, it seems like it is going to be a headache to implement as Rhapsody has many many files in different directories. What I think I am going to do instead is find a way of "deleting" the varying parts via a filter so that only the unchanged pieces are in the repository. – Aerophilic Jul 25 '13 at 20:21