Exclude files from pushing and pulling

I have a remote repository that is mirrored on a development site and downloaded to my local machine to work. When I push changes, they update the site with hooks.

Update What I need: The repository contains the entire project with a working "configuraion.php" for the development site (a working online resource for testing); Any developer can pull the roject and change only two path variables in config.php to run it; After that, this file should not be committed to the repository and should not be overwritten if changes are lost.

But I am getting errors from the repository. I tried:

  • Project downloaded
  • git update-index --assume-unchanged configuration.php

  • changed the file and at this point it seems OK

But when I try to pull changes (made by others) from the repository, I get this:

error: Your local changes to the following files would be overwritten by merge:
    configuration.php
Please, commit your changes or stash them before you can merge.
Aborting

      

Tried adding to ".git/info/exclude"

but no visible effect.

What am I doing wrong?

+3


source to share


2 answers


Can the file be configuration.php

tracked by other people? If so, then your remote repository will contain this file, and when you get to git pull

Git, try pushing this file into your local repository. Even though you haven't looked at the file, Git seems to be trying to connect it from the remote.

Update:

In the Git model, it doesn't make sense to ignore the remote file. Hence, if you insist on storing a file configuration.php

in a remote repository, you should not use that file in your local setup. One easy way would be to save another local PHP config file (for example configurationLocal.php

) and run it for local testing.



So, your workflow might be something like this:

  • git pull

    which will get the last configuration.php

    file
  • Copy configuration.php

    toconfigurationLocal.php

  • Add configurationLocal.php

    to your file .gitignore

    so it never gets tracked
  • Use configurationLocal.php

    for all checks on your device, etc.

During subsequent calls, there git pull

may be conflicts with configuration.php

, but this does not matter. In case of conflicts, you can simply accept the server version and then update the configurationLocal.php

script as needed.

+3


source


It is quite common that configuration files are required for a project. But it is also fairly common to have a sample file that provides excellent information for a standard configuration.

You can name this file with configuration.php.sample

instructions to copy this file to configuration.php

and change the information in the file where it needs to be changed.

If you can read the information to supplement this information, then you may be prompted to create "local_config.php".



In any case, the configuration files are not tracked in the repository, but the samples are executed. This allows information to be updated and locally changed files are simply not tracked.

Otherwise, if you make changes to a file that you don't want to push, you can strike out your changes (this is a great argument to never use git add .

and be responsible for specifying the files you want to add each time) to make changes to the repository and also pushes and pulls and then executes git stash pop

to revert your local changes.

And your helpful post from git even suggests that you are doing a stash. It can be as simple as doing it to get what you want if your need is unique to you and not to all the developers in your project.

0


source







All Articles