Git - Ignoring a specific modification to a config file

后端 未结 4 990
深忆病人
深忆病人 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:31

    Let me put some suggestions on how this might be done.

    When adding changes to the index you can use git add -p app.config and manually skip some of the changes in your file. If you don't add changes to the index before doing commit these changes would not be committed. This is a kind of 'local-only' solution. But it might be really boring to always see the file modified in git status report.

    All other suggestions might require changes in the architecture and there for can not be considered as 'local-only' solution. Anyway I think they might worth reviewing.

    The main idea for all changes is to have local file added to .gitignore which contains local system specific settings. We have used several slightly different solutions here.

    • You can have properties file with key-value pairs containing all local system specific values. This file should be updated manually. Then it is used on the application and merged into the application configuration. Details depend on the tools you are using. But I do believe this should not introduce any big difficulties but most likely would require application changes.
    • You can have app-original.config file in git repository and app.config file in git ignore list. The app.config file should be created manually from app-original.config file.

    What is really boring with all these solutions is that some manual work is required when the structure of config file is altered. For example on every config file update you should check if new properties have been introduced and update your local properties file. As well when you update your local file because of some application changes you need to remember to commit related changes in configuration files (remember your local files are in .gitignore).

提交回复
热议问题