简体   繁体   中英

How to keep a default config file in Git repository while allowing maintainers to use a custom version?

We have a .xml config file in a public Github repository, and we want to include a basic, default version of that .xml file available for new users.

However, the package maintainers want to be able to edit their personal .xml file without having to commit around it.

What's the cleanest way of keeping a default config file in a public Git repository while allowing maintainers to use a custom version?

I think the simplest solution is to have the application that uses this file check for a differently named XML file (eg suffixed with .local.xml instead) that takes precedence over the one in the default location. The one in the default location should be commited, while the path of the optional local override should be added to .gitignore .

The other solutions (eg --assumed-unchanged , filter drivers) are more fiddly and error prone, in my view.

The usual way is to ignore any change to that file locally:

git update-index --assume-unchanged file

Other solutions:

  • add and commit that file, then remove it from the index and add it to a .gitignore file
  • use a filter driver in order to restore the original content on commit

The advantage of the last two solution is that they enforce the policy of not committing any changes to the repo (as opposed to the first one which involves the developer of the local cloned repo to take the initiative to update the index).

在.xml文件上应用git update-index --assume-unchanged ,以便Git不会检查它们的修改,从而有效地“忽略”了这些文件上的修改

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