How to setup gitattributes to filter part of a file?

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:

  • How to force users to use email address in lowercase in GIT
  • git smudge/clean filters to only act on text (not binary) files
  • Git - filter before/on clone
  • What is wrong with this git smudge/clean filter?
  • Viewing git filters output when using meld as a diff tool
  • How to list the last occurance of a specific string in Terminal
  • 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?!

  • Remove a specific commit but keep all the commits afterward
  • Git commits are duplicated in the same branch after doing a rebase
  • Git client on the iPhone, possible? How?
  • Jenkins Git change submodule path
  • Get topic branch from gerrit
  • Is it possible to see staged / unstaged as tree in EGit & Eclipse
  • One Solution collect form web for “How to setup gitattributes to filter part of a file?”

    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.

    Git Baby is a git and github fan, let's start git clone.