Ignoring certain xml lines when merging
We are using git through sourcetree for a project involving HP UFT object repositories.
In our object repository files there is a date line, which is not automatically handled by git, so every time two repositories are merged we basically need to pick which date we want to keep. The date itself is never used and is not needed, and there is a date for every single object in the repository(~50 for each xml) so this is an annoying task.
Is there a way to make git ignore the date line? It doesn’t matter if the date stays the way it was instead of being updated. Alternatively have git always overwrite the old date with the new date. It looks like this (norwegian date):
<qtpRep:LastUpdateTime>6. mai 2014 12:03:22</qtpRep:LastUpdateTime>
The object repository files are xml files created/updated through UFT which means that the code is autogenerated, hence the continous update of dates within these files.
2 Solutions collect form web for “Ignoring certain xml lines when merging”
You could use a clear content filer in a
.gitattributes file in order to
(From Pro Git Book)
That would allow, automatically on
git add, to set the element
<qtpRep:LastUpdateTime> content to a fixed value instead of the auto-generated one.
*.xml filter=fixedDate git config --global filter.fixedDate.clean cleanDate
The script declared in the “clean”
fixedDate filter, here
cleanDate, can parse the content of the file being added, and replace the date by a fixed one.
That script and the
.gitattributes can be stored and distributed in the same git repo, but the filter needs to be activated by all users in order to be used consistently across all cloned repos.
(How do I write complete comments? All I managed to do with comments on stackoverflow was to write a single continous line of text.)
I created a repository and added a file called .gitattributes with a single line:
Then I ran the following in windows cmd:
git config --global filter.fixedDate.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'
This only returned the git config options. So I assume it ran correctly? Or does git return the options instead of an error message?
I then pushed an .xml file with the following content:
The file was pushed normally with no changes to the contents.
The explanation on http://git-scm.com/docs/gitattributes didn’t really help much.