2

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?

espeed
  • 4,754
  • 2
  • 39
  • 51
  • possible duplicate of [Add ignored config file to git repo as sample](http://stackoverflow.com/questions/3686270/add-ignored-config-file-to-git-repo-as-sample) – Karl Bielefeldt Aug 30 '11 at 12:25

3 Answers3

2

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.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • A similar option would be to simply omit the file entirely. Instead, write the app so that if the file is not present it generates a default file for the user. You would of course add that file to the .gitignore so that when it is generated it isn't committed. – Tekkub Aug 30 '11 at 09:13
1

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

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

manojlds
  • 290,304
  • 63
  • 469
  • 417