-3

I have a file with app configuration. I want to add this file to the repo so everyone could have basic configuration but ignore any changes in file if someone will want to modify configuration.

I know about assume-unchanged but it looks like it is only for local repo, when somebody will clone the repo and change this file git will mark it as modified.

Thanks.

aspirisen
  • 965
  • 13
  • 29

2 Answers2

0

Even if there is a technical solution to the problem, I don't think you should seek it. As a user of your repository, if I kept changing this one file and it wasn't showing up in my stage, I'd be very confused.

Mark the file as do not edit, either in a comment in the file, or in the readme if the file does not allow comments.

Then, if someone wants to make modifications to it and sees it in stage, it's their responsibility to set an ignore on the file.

halpdoge
  • 642
  • 7
  • 19
  • There is an agreement, so there will be no confusion when you change file and there are no modified state in git – aspirisen Dec 05 '19 at 18:15
  • Another solution is also to not have the file in git, add its name to gitignore, and create a script that generates the file, e.g. in Makefile, or a simple shell/bat script. That way, you can tell people to generate the file, yet their changes won't show up in stage. – halpdoge Dec 05 '19 at 18:17
  • Maybe it is good as workaround, but perfect solution will be is to ignore modifictions – aspirisen Dec 05 '19 at 18:18
  • 1
    Or add a pre-commit hook that prevents commits if that file is modified. – Daniel Mann Dec 05 '19 at 18:18
  • Typically though, it's the user's responsibility to set which files to ignore. It seems like a smell to enforce it. – halpdoge Dec 05 '19 at 18:19
0
  • Call your configuration config-template.conf and provide that through the repo.
  • In the README, instruct users to rename the template to config.conf which your application expects to find.
  • Add config.conf to your .gitignore.

The config.conf will not be tracked.

Donentolon
  • 1,363
  • 1
  • 10
  • 17