Answer the question
In order to leave comments, you need to log in
Ignoring local files in GIT?
Me and another programmer, we work with the project through a bare repository. The project has a file includes/config.php
that I have specific settings. To prevent these changes from being sent to the central bare repository, I added it to the .git/info/exclude
. Everything would be fine, but with this approach, problems of the following nature periodically arise:
1. Global changes have been made to the file includes/config.php
, which I should also have.
When we try to do this git pull origin master
, we get the following message:
error: Your local changes to the following files would be overwritten by merge:
includes/config.php
Please, commit your changes or stash them before you can merge.
Aborting
includes/config.php
, we successfully do git pull origin master
it, we restore the deleted file, and we hide the fact that changes have been made to this filegit update-index --assume-unchanged includes/config.php
(It is not clear why GIT does not automatically ignore these changes, because the file is in the exception.) $ git checkout test_branch
error: Your local changes to the following files would be overwritten by checkout:
includes/config.php
Please, commit your changes or stash them before you can switch branches.
Aborting
git rebase
. But this is not always acceptable, because the commit dates change. .gitignore
, but it does not depend on me and you need to somehow get out of this situation on your own. Answer the question
In order to leave comments, you need to log in
It is necessary not to store the configuration files themselves in the repository at all, but to store examples of configs there.
For example, your real config should be placed along the includes/config.php path. Then:
1. add the includes/config.php-distr file to the repository, which contains the structure, default settings, but does not contain any passwords, etc.;
2. by copying includes/config.php-distr to includes/config.php and then editing with passwords etc. create a real config. To prevent it from being in the repository, put it in .git/info/exclude.
3. add a paragraph about creating a config by copying an example with subsequent adjustments to the documentation for deploying the repository.
If you need to change something in the config example, edit includes/config.php-distr and commit. Next, edit the includes/config.php with your hands, but this does not get into the commits.
(It is not clear why GIT does not automatically ignore these changes, because the file is in the exception.)Excluding files means "do not automatically add this file to the repository". Since your file is already there, the exception is not relevant.
auto_prepend_file
, for example.
if I understood everything correctly - .gitignore will help you
otherwise - only dancing
You need to delete the file from the index
and if you need a reverse command to return to the index:
But the truth is, if this file is changed in the remote repository (newer version), then the local one will be overwritten again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question