How do I stop watching the changes in a particular file?

Asked

Viewed 246 times

7

The scenario is as follows. I work on a project that contains a JSON file with database configuration. Something like:

{
    "db_config": 
     {
        "conn_string": "server:localhost;user:db-user;password=db-pass"
     }
}

It turns out that I need to change these settings to run the project in my local environment, this because I use the remote database on a local server.

The problem is that whenever I change this file with my settings

  1. I need to remember not to add it before the commit; or

  2. I need to remember to change it before commit; or

  3. I just committing the file and "spoiling" the configuration of all my project colleagues.

Put the file in the .gitignore would cause it to be deleted from the remote repository.

How can I ask GIT to ignore all the changes I make in this file? And how can I reverse this if I need to change some configuration in this file later?

  • What I usually do is commit the empty file and then put it in .gitignore. Then, in production, the variables are either placed in env or that file is overwritten on the server by another with the complete keys.

  • I suggest working with profiles, one for dev and one for Prod. Each will have its configuration and will not need to change them anymore.

  • I appreciate the tips, but I just want a GIT command to stop "observing changes" in a given file. The scenario is fictitious =D

  • @jbueno understood your need, you just want to avoid modifications to a particular configuration file, but it needs to exist in advance anyway, see if this resolves http://stackoverflow.com/a/21756612/1518921

1 answer

5


You can use the assume-unchanged for that reason.

It would look something like this:

git update-index --assume-unchanged path/file

And to return to "obervar", just do this:

git update-index --no-assume-unchanged path/file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.