How to setup gitattributes to filter part of a file?

左心房为你撑大大i 提交于 2019-12-01 11:37:27

I do not know how to do it exactly on windows, but I do know how I would do it on *nix.

I would write a sed/bash script (called myscript) which removes those lines from the file when they are checked-out by git using a git "smudge" filter.

So in "$GIT_DIR/info/attributes" I would add:

{sln filename} filter=myfilter

And define the smudge-part of the filter in the "$GIT_DIR/config" file:

[filter "myfilter"]
    smudge={path to myscript}

For Linux I would even just call sed directly like this:

[filter "myfilter"]
    smudge=sed '/GlobalSection(SubversionScc)/,/EndGlobalSection/ d'

This is maybe something you can take over in windows using git bash.

Be careful when you want to checkin changes to the file, as it will checkin the "smudged" version. You can define a "clean" filter for this which adds the svn statements again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!