2

I'm confused about gitattributes.

I'm not sure if what I'm trying to do is possible: I have a settings file that my IDE is generating for my project and this file get's updated very often. It's basically a text file but it's recommended not to edit it in text mode. I allow my self adding and editing certain parts of the file but I let the IDE's GUI do the rest because otherwise I may encounter problems.

Part of the file is changed by the GUI and some of it is changed by me. I want git to ignore changes or added lines that the GUI does but keep track of changes that I make.

I can fit into a pattern the changes that the GUI and vise-versa. For example, the command below can print only the lines I want to tell git to track:

egrep -v (WORDS|THAT|APPEAR|IN|LINES|I|DON'T|WANT|GIT|TO|TRACK) <setting-file>

I came across gitattributes here and here. So I created a filter with the command above and I put it in smudge and clean in my ~/.gitconfig. I've managed to make it work but The problem is: I don't want git to actually remove the lines that don't get through the filter. I just want git to ignore any changes to these lines.

Hope I made myself clear.

Community
  • 1
  • 1
Doron Behar
  • 2,606
  • 2
  • 21
  • 24

1 Answers1

2

No, Git can't do that.

If your IDE's config format supports including files, you can split the settings you want into a separate file (tracked by Git) and just include it into the main config (which you should add to .gitignore so it doesn't bother you.)

If it doesn't, you still might find a way to sneak the settings in without tracking the main config. If you're tying to enforce code style settings, for example, you should try .editorconfig.

That's about as far as automation can take you. There's also a semi-manual approach suggested by @jthill where you write a script that changes the settings you want, but you'll have to remember to run it at appropriate moments.

(Just a remark: storing IDE or editor files—save for .editorconfig—is considered a bad practice in any project with more than one developer/machine. The conflicts are almost inevitable, and you can encounter them even if you're all alone but have two machines—differencies like instalation paths might percolate into the config and make your life hell, breaking the build on one machine every time you commit the config on the other.)