Git - Ignoring a specific modification to a config file

后端 未结 4 989
深忆病人
深忆病人 2020-12-03 20:02

I have a config file in our project that holds a connection string to the database, as well as several application settings, e.g:

...


        
4条回答
  •  一整个雨季
    2020-12-03 20:35

    I do not think git has such facility. And the proposed way of managing the app.config file, treating part of the file version controlled and other part not, does not smell right to me.

    In your situation I would seek a way to arrange the app.config to be generated from two files. The ConnectionString setting would be placed in user created (build) configuration file, and the other parts would be put in some sort of template file (conceptually speaking). The user created configuration file could be added to the .gitignore file. The template file would be controlled by git. We would need to have a method to build the app.config file by applying the settings in your build configuration file to the template file.

    We are lacking background information about the development setting to tell how all this could be implemented. If you are using make or ant or similar thing, then this would be a simple dependency and rule to create the app.config to make sure the file is created if it does not exist or if the build config file or template file change. Also the natural choice for how to generate the app.config file from the template file depends on your build environment and the nature of the app.config file. For longer than couple of lines of text, even a shell script can be used for simple expansion of a given template file easily (couple of lines of lines to expand ${VARIABLE} constructs, but gets more complicated if the file needs to include dollar signs or back ticks or backslashes etc). More complicated expansion we could use eruby, or eperl or similar thing (even perhaps PHP). The app.config file could also be generated manually whenever you need to change the setting. But all this is somewhat useless speculation without further context.

提交回复
热议问题