I have a file database.properties
which has
password = something
So whenever I have to test something I will have to change this line to my local password. Everybody in the team will have their own local password.
I guess I will have to do one of the following :
Every time I commit I should not add
database.properties
to index (I don't want toignore
this file), but when there are too many files it's easy to miss this file.Undo the changes before committing, but most of the time I forget to do this.
Creating a profile may be a way to achieve this but even will have similar issues as
database.properties
.
I have checked Can git ignore a specific line? and How to tell git to ignore individual lines, i.e. gitignore for specific lines of code.
From temporarily ignoring files I see that we can do
git update-index --assume-unchanged <file>
but I will have to do this every time.
All the above references were asked/written before 3-4 years. So I just want to know If there is a better way to ignore just that one line.
EDIT
Following @VonC's answer I have tried to add a filter in .git/info/.gitattribute
{directory_path}/database.properties filter=password // I have given the correct directory path.
And I have added smudge
and clean
scripts as:
git config --global filter.password.smudge ~/smudge.sh
git config --global filter.password.clean ~/clean.sh
(When I run ~/smudge.sh
and ~/clean.sh
it replaces password= something
line correctly. So the scripts are correct.)
But when I add/commit the database.properties
, there seems to be no affect on database.properties
file. (I am guessing ~/clean.sh
should run when I add it to index)
What am I doing wrong?