Why does git add&remove the Storyboard <classes> section repeatedly?

When saving the storyboard and committing the changes to git, the chances are good that the whole <classes> section will be removed from or added to source control (git). I am using git on the command line, not the XCode integrated UI.

First it looks like this:

  • git checkout from remote
  • Extracting subdirectory from a git repo into another repo and keeping dir structure?
  • How does git tag --contains work?
  • Redirecting stdout/stderr/stdin of 'git clone'
  • Storing Configuration File
  • What sbt plugins are available for frequent (multiple times per day) releases of a project from git?
  • +    <classes>
    +        <class className="CPTGraphHostingView" superclassName="UIView">
    +            <source key="sourceIdentifier" type="project" relativePath="./Classes/CPTGraphHostingView.h"/>
    +        </class>
    +    </classes>

    And in the next commit it looks like that:

    -    <classes>
    -        <class className="CPTGraphHostingView" superclassName="UIView">
    -            <source key="sourceIdentifier" type="project" relativePath="./Classes/CPTGraphHostingView.h"/>
    -        </class>
    -    </classes>

    Why is that, and, more importantly: how can I stop that?

  • How to get remote branch name in git pre-push hook
  • git submodule add failed with bitbucket repo
  • Can “git push” hang on the same %?
  • Cant push changes back to Launchpad using git-bzr
  • How to find previous merge commit
  • What is the meaning of :/ (colon, forward slash) in the 2.0 version of git add --update syntax?
  • 2 Solutions collect form web for “Why does git add&remove the Storyboard <classes> section repeatedly?”

    (this answer is based personal experience, and is not a formal one)

    The classes section in the .storyboard xml file lists all the view controllers you have in your project in order to

    1. Allow the Assistant Editor show the right source file when you select a UI element in the Interface Builder, and
    2. Allow the Identity Inspector (right panel) to present options for Custom Class.

    I guess this section is a cache, being retired when both of the two uses listed above haven’t been used for a while.

    The fact that this section turned up in the first place implies it is safe to ignore, since it is auto-generated on need. If you already have it committed, and subsequently have it appear as removed on diff, open the Identity Inspector, drop-down the list of classes available under Custom Class, and see how the whole section exists once again.

    In my experience the removal only happens if you open the storyboard and have class existence related errors. An example of this is opening the storyboard while a merge conflict is not yet resolved. One or more classes might not be parse-able. In this case Interface builder seems to be removing the entire section and not only the offending class.

    For me it is easily fixed by opening the storyboard again after the patch is ready in case i see the removal. If all problems are resolved, the section is regenerated. If it isn’t, it means I have a problem with project settings and i shouldn’t be committing anyways.

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