espeed
espeed

Reputation: 4814

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?

Upvotes: 2

Views: 354

Answers (3)

Mark Longair
Mark Longair

Reputation: 467231

I think the simplest solution is to have the application that uses this file check for a differently named XML file (e.g. 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 (e.g. --assumed-unchanged, filter drivers) are more fiddly and error prone, in my view.

Upvotes: 2

manojlds
manojlds

Reputation: 301147

Apply git update-index --assume-unchanged on the .xml files so that Git will not check them for modifications, effectively "ignoring" the modification on those files

Upvotes: 1

VonC
VonC

Reputation: 1324407

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).

Upvotes: 1

Related Questions