I
I
Ivan Panteleev2013-01-31 13:20:57
git
Ivan Panteleev, 2013-01-31 13:20:57

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.phpthat 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

It's not scary, we delete the file includes/config.php, we successfully do git pull origin masterit, we restore the deleted file, and we hide the fact that changes have been made to this file
git 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.)
2. After the previous step, another problem appears - it is not possible to switch to any branch that was created earlier.
We receive a message:
$ 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

In this case, only helps git rebase. But this is not always acceptable, because the commit dates change.
All this is reminiscent of dancing with a tambourine.
I understand that you can make a separate local settings file and add it to .gitignore, but it does not depend on me and you need to somehow get out of this situation on your own.
What are the solutions to this problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
avorobiev, 2013-01-31
@Yekver

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.

A
akral, 2013-01-31
@akral

(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.
You can transparently add your changes using auto_prepend_file, for example.

D
Diam0n, 2013-01-31
@Diam0n

if I understood everything correctly - .gitignore will help you
otherwise - only dancing

A
Andrey Izman, 2014-04-29
@mervick

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 question

Ask a Question

731 491 924 answers to any question