简体   繁体   中英

Changed tracked file in git and allow branch changes

I have the following case: On the upstream(original) server I have a template file which show a basic configuration for the program. This file must stay there.

I forked the project and wish to change the template file, on my remote I have two branches: master, devel. I wish to change the file on both but not to commit it since I will send a merge request in the future and the basic configuration must be kept.

Currently I tried 3 things:

  1. Keep the file unchanged when changing branches and committing (low tech solution).
  2. use: git update-index --assume-unchanged . This sounded like the best solution for me, the problem with this is that I can't change branches between the master and devel without committing (Git wouldn't allow it).
  3. Untrack it. As I said this is not real solution since it must stay in the repo.

Any suggestions/Best practices that might help me?

This is a common problem. You have some config file or template that has to remain a certain way in the repo, but you want to be able to change it locally in your checkout for testing or deployment or whatever.

The simplest solution is to have two files. One is the standard config/template that comes with the repository. This is checked in. The other is an overlay file. This overrides any of the files in the standard config. This doesn't get checked in, or it's checked in and left blank, and added to .gitignore .

For example, here's a master.config file that's checked in, and a local.config file which isn't.

master.config
    some: thing
    database:
        type: mysql
        host: localhost
        user: test
        pass: test

local.config
    database:
        host: production.db
        user: production_user
        pass: s3kr3t

The resulting config will be a merge of the two.

    some: thing
    database:
        type: mysql
        host: production.db
        user: production_user
        pass: s3kr3t

You will have to write the code to do the merging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM