17

A .gitignore file allows to ignore files from version controlling them at all.

We have a different situation: we want to place in the repository some configuration files, that need to be changed on per-machine basis (db access info for instance).

We do want to distribute them, as placeholders, so we include them into the repository. However, later we want any changes to them to be ignored, for all developers.

Is there a way to do it?

Note:

The question Git: Ignoring Version-Controlled Files is actually the same. However, none of the answers answered the question, including the accepted one.

Edit:

  • Is there a way to do --assume-unchanged to a pattern rather than a single file?
  • Is there a way to propagate this command to the repositories of other developers?
Community
  • 1
  • 1
shealtiel
  • 8,020
  • 18
  • 50
  • 82
  • 1
    possible duplicate of [Prevent local changes to get pushed in Git](http://stackoverflow.com/questions/2173726/prevent-local-changes-to-get-pushed-in-git) – Mauricio Scheffer Feb 16 '11 at 01:01
  • http://stackoverflow.com/questions/4743770/git-collaboration-how-to-manage-configuration-files, http://stackoverflow.com/questions/1396617/git-committing-machine-specific-configuration-files – wnoise Feb 16 '11 at 01:19
  • Possible duplicate of probably all of these: http://stackoverflow.com/search?q=[git]+%2Bassume-unchanged – Cascabel Feb 16 '11 at 01:21
  • All this about duplicates said, I *completely* agree with mathepic: the solution isn't to work around version control, the solution is to give your program the ability to choose between configurations. – Cascabel Feb 16 '11 at 01:39

2 Answers2

47

I define the following aliases in my .gitconfig file:

[alias]
  ignore = update-index --assume-unchanged
  unignore = update-index --no-assume-unchanged

That should do exactly what you want: running git ignore some-file will treat the file as unchanged no matter what you do to it, until you run git unignore some-file.

Adrian Petrescu
  • 16,629
  • 6
  • 56
  • 82
  • Is there no way to ignore whole directories? – keiki Dec 12 '13 at 08:04
  • 1
    See http://stackoverflow.com/questions/12288212/git-update-index-assume-unchanged-on-directory: `git ls-files -z path/to/directory | xargs -0 git ignore` – maff Dec 10 '15 at 08:43
3

I know this kind of dodges the issue, but I would have a ".defaults" file for each, and then change this. This helps with the configuration energy anyway - what if someone who has a custom configuration wants to change the defaults?

Don't ignore the .defaults, ignore the actual thing. Maybe have a script that copies the .defaults to the regular ones if they don't already exist.

alternative
  • 12,703
  • 5
  • 41
  • 41