If your file is of a specific type, you can declare a content filter driver, that you can declare in a .gitattributes
file (as presented in the “Keyword expansion” of “Git Attributes”):
*.yourType filter=yourFilterName
(you can even set that filter for a specific file, if you want)
Implement:
-
yourFilterName.smudge
(triggered ongit checkout
) andgit config --global filter.yourFilterName.smudge 'sed "s/isPhoneGap = .*/isPhoneGap = true/"'
-
yourFilterName.clean
(triggered ongit add
)git config --global filter.yourFilterName.clean 'sed "s/isPhoneGap = .*/isPhoneGap = false/"'
Your file would appear unchanged on git status
, yet its checked out version would have the right value for isPhoneGap
.
Note: in the comments, ohaal and Roald suggest to isolate the sed
calls in a separate helper.sh
script:
sed "s/isPhoneGap = .*/isPhoneGap = true/" "$@"