0

I am looking to filter out specific parts of a json file so that the given part of the file does not get pulled into a git repository. My use case is that I am setting up a repository to keep some working files, including settings for vsCode. I have a plugin for window colors that sets different colors for different windows that are open. The current color is saved in the .vscode/setting.json file for that window.

I found where it is possible to use the .gitattributes file to apply a filter to a file or set of files, and then use "$git config" to remove certain lines from what is committed, based on a sed command per this previous question.

I would like to apply this to the "workbench.colorCustomizations" object within the following json file, so that this object does not get committed, while other settings in the file may be committed, such as the "editor.formatOnPaste" object. Does anyone know of a way to do this?

{
    "workbench.colorCustomizations": {
        "activityBar.background": "#102D56",
        "titleBar.activeBackground": "#173F79",
        "titleBar.activeForeground": "#F8FAFE"
    },
    "editor.formatOnPaste": true
}
  • suggestion: write 2 scripts, one that takes settings.json content as an input and outputs just the parts you want to save, one which takes 2 jsons as input (the current settings.json, and the last saved settings), and returns the updated settings.json content. – LeGEC Jun 01 '22 at 03:50
  • IMHO : you could simply run those scripts outside of git, and version only the poduction of the first script (e.g: `settings.saved.json`). I think it would be a bit cumbersome to handle content changes correctly on ceckout if you used it as a content filter. – LeGEC Jun 01 '22 at 03:54

0 Answers0