-1

I created an svg file with Incskape. It contains a text element like this:

<text
  [..]><tspan
  [..]
    style="font-style:normal;fill:#c913ff;fill-opacity:1">My Text</tspan></text>

I want to use git to keep track of my changes. Since git uses whole lines to look for changes I edit the svg file with an text editor to separate the style attributes from the text itself.

<text
  [..]><tspan
  [..]
    style="font-style:normal;fill:#c913ff;fill-opacity:1">
My Text
</tspan></text>

This way I can change style and text in different commits without effecting the other.

Unfortunately Inkscape rewrites the svg file with each save and the text goes back into the same line with the style. :(

Is there a way to prevent Inkscape from doing this?

I know there might be a workaround by using some kind of variables for the style and change the values of the variables in another part oif the file. But I don't want to do that.

2 Answers2

0

The following workaround works for me.

When I save the file as normal SVG instead of Inkscape SVG the file is formatted as I want it to be.

<text
   transform="scale(0.97808647,1.0224045)"
   id="text3779"
   y="396.1929"
   x="159.78862"
   style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;line-height:0%;font-family:Corbel;-inkscape-font-specification:'Corbel Bold';letter-spacing:0px;word-spacing:0px;fill:#ff9715;fill-opacity:1;stroke:none"
   xml:space="preserve"><tspan
     style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:124.21698761px;line-height:1.25;font-family:Corbel;-inkscape-font-specification:'Corbel Bold';fill:#ff9715;fill-opacity:1"
     y="396.1929"
     x="159.78862"
     id="tspan3781">My Text</tspan></text>

However, this is only a workaround since the Inkscape-SVG might have some advantages over the normal SVG.

0

You could write a clean filter for Git so that your svg file gets indented before staging. You would put something like this in your .gitattributes file (create it in your repository root if you don't have one already):

*.svg filter=indent

Then adjust your git config to tell git what the filter does. Assuming you have indent installed here:

git config filter.indent.clean indent
git config filter.indent.smudge cat

This will run all your svg-files through a program called "indent" before staging them, so they appear to be nicely formatted in your repo and the log will look nicer. When checking files out, they are ran through cat which does not modify the file.

1615903
  • 32,635
  • 12
  • 70
  • 99