Reputation: 95
I have a repository which includes files that are generated when a third party executable is run. I need to track the files that are generated by this executable, to allow me to sync the executable settings between users.
Let us call this file "executable_settings.json"
The file can change in 2 ways:
Is there a way to get git to automatically ignore changes to executbale_settings.json, according to a rule? I would like to find a way to have changes of type 2 not appear as changes to git unless there was also a change of type 1 at the same time.
Upvotes: 0
Views: 361
Reputation: 76964
The best way here is to use a smudge and clean filter. These are outlined in the gitattributes(7)
documentation, but to summarize, if you write an entry in .gitattributes
like so:
executable_settings.json filter=exec-settings
and then add the following to your config:
[filter "exec-settings"]
clean = sed -e '/Edited On:/d'
then when you add the file to Git with git add
, it will deleted all the lines which contain “Edited On”. Note that this won't intrinsically prevent them from being marked modified by git status
, but it will prevent those lines from being checked in.
Note that you can use a different command, such as jq
or a script, that would filter out the entries you don't want. Once you're happy with the filter, you should add .gitattributes
, run git add --renormalize .
to fix the files in the repository, and commit.
I should point out that this is generally local to your system. There's no way to include this configuration in the repository such that it's automatically invoked. This is because doing so would allow arbitrary code execution. However, you could add a setup script to your repository that installs this configuration locally as part of your project.
Upvotes: 1