As Melpor said, trajectory would be critical, but he misses the point of your question. You said "almost hitting." So, there would not be a collision.
Depending on the trajectory, the Earth, if it survived, would likely be moved to an elliptical or hyperbolic orbit. Hyperbolic means ejected from the Solar system.
But more important effect is the gravitational disruption of Earth. Depending on the density of the other planet and the exact distance of its closest approach, Earth may be tidally ripped apart -- if it comes within the Roche's limit of the other planet. Likewise, that other planet could suffer the same effect.
I'm not sure what the magnetic field effect would be. Magnetic field of the Earth is determined by flow within the core, but also the rotation of the planet.
Einstein never had a theory of polar change, but he did find favor with Charles Hapgood's theory of crustal displacement. In fact, Einstein wrote the foreword to Hapgood's 1958 book. If such crustal displacement is possible, then such a strong gravitational disturbance could initiate such a shift. But I'd be more concerned with the tidal effects of a near pass. If we weren't within Roche's limit, we'd have massive earthquakes, volcanic eruptions and tidal waves. Goodbye civilization!