如何设置gitattributes来过滤文件的一部分? [英] How to setup gitattributes to filter part of a file?

查看:466
本文介绍了如何设置gitattributes来过滤文件的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010和git(git svn)。我的同事用Ankhsvn插件使用纯svn。

当我尝试打开启用Git Source Control Provider的文件时,Visual Studion抱怨:


源代码管理插件

当前的解决方案或项目由adifferen源代码管理插件控制,与您选择的源代码管理插件相比较。如果您更改了源代码管理插件,则活动的解决方案或项目将被关闭。

您要继续吗?

当我点击是时,打开一个空的解决方案。
当我点击否,解决方案项目旁边的所有git特定图标都丢失(我仍然在解决方案资源管理器中看到分支名称),每当我打开解决方案时,我都会收到有关源代码管理插件的提示。

当我克隆我的同事创建的svn仓库时,sln文件包含以下内容:

lockquote

GlobalSection(SubversionScc)= preSolution

Svn-Managed = True

Manager = AnkhSVN - Subversion支持Visual Studio

EndGlobalSection


我已经删除了这部分,现在解决方案在Git源代码管理提供程序激活时没有问题地打开,但是当您选择Ankhsvn Provider时

我想告诉git在pull(git svn fetch)时删除.sln文件的这一部分,并在我提交时添加它(git svn dcommit)。这是可能的通过gitattributes和如何做到这一点?

编辑:

现在我已经添加


solutionname.sln filter = ankhsvn


to $ GIT_DIR / info / attributes

  [filterankhsvn ] 
clean = sed'/ ^ Global $ / r ../ankhsvnsection'
smudge = sed'/ GlobalSection(SubversionScc)/,/ EndGlobalSection / d'


到我的.git / config文件。

ankhsvnsection包含被删除的secton涂抹操作。
我似乎没有做任何事情!

解决方案

我不知道如何在Windows上完全做到这一点,但我知道如何在* nix上执行。



我会编写一个sed / bash脚本(称为myscript) git使用 gitsmudge过滤器检出。



所以在$ GIT_DIR / info / attributes中我会加上:
$ b $ pre $ {sln filename } filter = myfilter

在$ GIT_DIR / config中定义过滤器的smudge部分file:

  [filtermyfilter] 
smudge = {到myscript的路径}

对于Linux,我甚至可以直接调用sed:

<$ p $
smudge = sed'/ GlobalSection(SubversionScc)/,/ EndGlobalSection / d'
[filtermyfilter p>

这是m您可以使用git bash在窗口中接管某些东西。



当您要检入文件更改时,请小心,因为它会检查污迹版本。您可以为此定义一个干净的过滤器,再次添加svn语句。


I am using Visual Studio 2010 and git (git svn). My coworker uses pure svn with the Ankhsvn plugin.

When i try to open the file with the Git Source Control Provider enabled, Visual Studion complains:

Source Control Plug-in
The active solution or project is controlled by adifferen source control plug-in than the one you have selected. If you change the source control plu-in, the active solution or project will be closed.
Do you want to continue?

When i click yes an empty solution is opened. When i click no, all the git specific icons next to the solution items are missing (i still see the branch name in the solution explorer) and i get prompted about the Source Control Plug-in every time i open the solution.

When i clone the svn repository which my coworker created the solution sln file contains the following

GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection

I have deleted this section and now the solution opens without problems when the Git Source Control Provider is activated but complains when you select the Ankhsvn Provider - the situation is reversed.

I would like to tell git to remove this part of the .sln file during a pull (git svn fetch) and add it when i commit (git svn dcommit). Is this possible through gitattributes and how to do it?

EDIT:

I have now added

solutionname.sln filter=ankhsvn

to $GIT_DIR/info/attributes

and

[filter "ankhsvn"]
  clean=sed '/^Global$/ r ../ankhsvnsection '
  smudge=sed '/GlobalSection(SubversionScc)/,/EndGlobalSection/d '

to my .git/config file.

ankhsvnsection contains the secton that is removed by the smudge operation. I does not seem to do anything?!

解决方案

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.

这篇关于如何设置gitattributes来过滤文件的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆