1

I have some commits that are local configuration changes so we obviously do not want it to propagate to the master when merging. I guess this mean the merging will need to do some cherry-pick or to explicitly undo the merge of these commits. Is there some way to tell the merge to exclude them? Or even mark them initially as non mergeable.

Our current practice is do not even commit them to local. This is disturbing in two ways: we do not keep track of them, and git status keep telling us that we should add them (and we can not exclude them in a .gitignore as other changes need to propagate).

arivero
  • 777
  • 1
  • 9
  • 30
  • 1
    Your title is misleading, because it's not about Git configuration changes but (from the perpective of Git!) commits to regular versioned files that should not be pushed. I'd suggest looking at Git hooks and additionally at a CI pipeline that raises a red flags when bogus changes are pushed. – Ulrich Eckhardt Apr 11 '21 at 15:02
  • @UlrichEckhardt deleted "configuration", sorry about the mislead – arivero Apr 11 '21 at 15:07
  • @arivero Would this help? – knittl Apr 11 '21 at 15:08
  • @arivero why can't you ignore the configuration file? I don't understand that part of your question – knittl Apr 11 '21 at 15:09
  • Because some options should really be propagated to the master, only proper local things (port numbers, directory numbers, etc) are to be ignored. – arivero Apr 11 '21 at 15:32

1 Answers1

1

Ideally, you would commit those environment-dependent settings in your branch.
But in a conf.dev file, instead of conf directly (assuming here this is about configuration file: replace "conf" by the actual file whose changes you need to "selectively ignore")

The conf file itself should be ignored by Git and only generated.

You would store an conf.tpl template file with placeholder values in it.

That allows you to generate the right conf file locally, and automatically on git clone/git checkout.

The generation script will:

  • search the right values for any data in the conf.<branch_name> file
  • replace the placeholder value in conf.tpl to generate the right conf (that can be ignored by Git)

For that, do register (in a .gitattributes declaration) a content filter driver.

smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

The smudge script will generate (automatically, on git checkout or git switch) the actual conf file as mentioned above.
Again, the generated actual conf file remains ignored (by the .gitignore).

See a complete example at "git smudge/clean filter between branches".

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